/**
* noka db grid version 1.0
* rebin 2013-05-03
**/
//--------------去掉html的空格符------------------------------
String.prototype.hTrim = function(){
    return this.replace(/(\&nbsp\;)/g,"");
};
var NKDBGrid = Class.create({
    version: '1.0',
    //=================初始化方法===============================
    initialize : function(dbModel) {
    	this.dbModel = dbModel;						 //数据模型
    	this.id=dbModel.nkid;
    	this.showcell = dbModel.options.isCellBody;						//是否显示格子列表
    	this.columnModel = dbModel.columnModel || [];//列数
    	this.colinitModel = dbModel.colinitModel || [];
        this.rows = dbModel.rows || [];				 //行
        this.options = dbModel.options || {};		 //全局选项
        this.target=null;
        this.idHideHead=dbModel.options.idHideHead || false;//是否隐藏列
        this.isHideBottom=dbModel.options.isHideBottom || false;//是否隐藏列
        this.url=dbModel.options.rooturl; //ajax  url
        this.sql=dbModel.options.sql;
        this.treesql = dbModel.options.treesql;
        this.countsql = dbModel.options.countsql;
        this.treeselectfiled = dbModel.options.treeselectfiled;
        this.findtreenode = dbModel.options.findtreenode;
        this.heigth=this.options.height;//高度
        this.width=this.options.width;//宽度
        this.scrollBarWidth = 20;//滚动条宽度
        this.lanage=dbModel.lanage || {};//语言 文件
        this.showpage=1;//当前显示页
        this.syscells=dbModel.syscells || [];//附加列
        this.subTable= dbModel.subTable || {};//子表 
        this.inputData=dbModel.options.inputData || [];//输入框数据绑定
        this.formNull=dbModel.options.formNull;
        this.formConfirmation=dbModel.options.formConfirmation;//确认信息
        this.initdescorname=this.options.pagedescorname;
        this.initdescorasc=this.options.pagedescorasc;
        this.initdescorascimg=null;//当前排序列对像
        this.tempdescorascimg=null;
        this.tempdescorascimgFixed=null;
        this.LastRown=0;//总记录数，用户自动刷新
        this.editCells = this.options.editCells;//编辑列  editCells="[{cell:'MENUID',attribute:'',oninitedit:'',oninitedit:'',oninitedit:'',cfg:{type:'input',allownull:false}},{cell:'MENUID2',cfg:{type:'input',allownull:false}}]
        this.rowNumber = 0;//行记数器
        this.noData = false;//没有数据
        this.editSubmitColor = this.options.editSubmitColor;
        this.endtSubmitAction = this.options.endtSubmitAction;
        this.editOnSubmit = this.options.editOnSubmit;
        this.editOnReturn = this.options.editOnReturn;
        this.editAllSubmitAction = this.options.editAllSubmitAction;
        this.editNowCellRow = {rowIndex:0,cellIndex:0};//当前编辑的行列号
        this.editAddNowHash =new Hash();//记录新增行
        this.oninit=this.options.oninit;//在初始化之前调用
        this.onresize = this.options.onresize;//改变大小时调用
        this.autosize = this.options.autosize;//自适应大小,默认为true
        this.isAginSize = false;//是否二次加载大小
        this.selectMode = this.options.selectMode;//下拉模式下
        this.autowidth = (undefined!=this.options.autowidth?this.options.autowidth:true);
        this.sumcells = false;//汇总列
        this.sumcellidexs = "-1";
        this.lastRowIdex = 0;
        this.onSetSumValue = this.options.onSetSumValue;//在初始化汇总列时
        this.foldingLine = (undefined!=this.options.foldingLine?this.options.foldingLine:false);//默认为false
        this.flodingButton = (undefined!=this.options.flodingButton?this.options.flodingButton:true);//折行按钮
        this.insertBlankRow = (undefined!=this.options.insertBlankRow?this.options.insertBlankRow:0);//初始时插入空行数
        this.insertBlankRowEnd = 0;//已经插入的行
        this.editOnSubmitForm = this.options.editOnSubmitForm;//提交时需要提交的外部表单数据
        this.editOnSubmitAll = this.options.editOnSubmitAll;//在编辑时，全部提交时需要调用的外部
        this.sort = (undefined == this.options.sort?true:this.options.sort);//列排序
        this.setkey = this.options.setkey;
        this.oautowidth = (undefined!=this.options.oautowidth?this.options.oautowidth:true);
        this.insertDatas = [];
        this.rowHeight = 0;//行高
        this.rowDatas = [];//数据
        this.insertFun = function(a,b){return true;};
        this.tempcellsPars  = new Hash();//单元格编辑临时参数
        this.minpage = (undefined==dbModel.options.minpage?false:dbModel.options.minpage);//迷你分页模式
        this.pagecode = (undefined==dbModel.pagecode?10:dbModel.pagecode);//页码数量
        this.sumsql=dbModel.options.sumsql;//在树形状态下，指示用那一个sql作为统计sql  sql|treesql
        this.treeclick = (undefined==dbModel.options.treeclick?function(a){return true;}:dbModel.options.treeclick);
        this.cellname = dbModel.options.cellname;
        this.dataurl = undefined == dbModel.options.dataurl?this.url+'/nk'+this.id+'db.ndbgrid':dbModel.options.dataurl;//数据加载url
        this.subtableurl =undefined == dbModel.options.subtableurl?this.url+'/nokatag_subdbgrid/subgrid'+this.id+'.sgr':dbModel.options.subtableurl;//子表url
        this.exporturl = undefined == dbModel.options.exporturl?this.url+'/outexcel'+this.id+'.gridexcel':dbModel.options.exporturl;
        this.fxeidcell = undefined == dbModel.options.fxeidcell?true:dbModel.options.fxeidcell;
    },
    //=================显示表格================================
    show : function(target){
    	var bodyHtml=$(target);
    	var self=this;
    	this.target=target;
    	try{
    		if(undefined!=self.selectMode){
    			$(self.selectMode+'_sboddiv').setStyle({width:self.width});
    		}
    	}catch(e){}
    	self.userInit();
    	self.CreateWidthTable();
    	bodyHtml.innerHTML=self.CreateTitle(self.options.title);//添加标题
    	bodyHtml.innerHTML+=self.CreateTableHead();//显示表头
    	bodyHtml.innerHTML+=self.CreateBody();//显示表体
    	bodyHtml.innerHTML+=self.createSumcells();//自定义会总列
    	bodyHtml.innerHTML+=self.CreateCustom();//自定义统计栏
    	bodyHtml.innerHTML+=self.Createbottom();//底部菜单
    	bodyHtml.innerHTML+=self.CreateSetMenu();//设置菜单
        bodyHtml.innerHTML+=self.resizeMarkerLine();//拖动列宽时的标位线
    	self.selectMobdeEvent();
    	self.setPageStyle();
    	self.reSetBodyHeight();//重设度高
    	self.LoadData();//加载数据
    	self.ObjectAddEvent();//加载事件
    	self.TimeAutoRefresh();//自动刷新
    	self.DraggableCellWidth();//拖动列宽
    	self.hideHeadBottom();//隐藏表头和表底部
    	self.keypressEvent();//键盘事件
    	self.documentEvent();
    },
    rshow: function(target){
    	var bodyHtml=$(target);
    	var self=this;
    	this.target=target;
    	try{
    		if(undefined!=self.selectMode){
    			$(self.selectMode+'_sboddiv').setStyle({width:self.width});
    		}
    	}catch(e){}
    	self.userInit();
    	self.CreateWidthTable();
    	bodyHtml.innerHTML=self.CreateTitle(self.options.title);//添加标题
    	bodyHtml.innerHTML+=self.CreateTableHead();//显示表头
    	bodyHtml.innerHTML+=self.CreateBody();//显示表体
    	bodyHtml.innerHTML+=self.createSumcells();//自定义会总列
    	bodyHtml.innerHTML+=self.CreateCustom();//自定义统计栏
    	bodyHtml.innerHTML+=self.Createbottom();//底部菜单
    	bodyHtml.innerHTML+=self.CreateSetMenu();//设置菜单
    	bodyHtml.innerHTML+=self.resizeMarkerLine();//拖动列宽时的标位线
    	self.selectMobdeEvent();
    	self.setPageStyle();
    	self.reSetBodyHeight();//重设度高
    	self.LoadData();//加载数据
    	self.ObjectAddEvent();//加载事件
    	self.TimeAutoRefresh();//自动刷新
    	self.DraggableCellWidth();//拖动列宽
    	self.hideHeadBottom();//隐藏表头和表底部
    	self.keypressEvent();//键盘事件
    },
    //-------------------------------------------------
    setMenuInit : function(){
    	var self = this;
    	setTimeout(function(){
    		$('nk_'+self.id+'_setimage').click();
    		$('nk_'+self.id+'_setmenu_div').hide();
    	},10);
    },
    //--------------------------------------------------
    documentEvent : function(){
    	var self = this;
    	document.observe('widget:noka_grid_reinit',function(event){
    		try{
    			$(self.id).reinit();
    		}catch(e){}
    	});
    	document.observe('widget:noka_grid_resize',function(event){
    		self.resize();
    	});
    },
    //---------------手动设置列固定-----------------------------------
    setFxiedCell : function(index){
    	var self = this;
    	//------------清除设置--------------------------------------
    	$$('#nk_'+self.id+'_head_table th[class~="nkfixed"]').each(function(alink,index) {
    		$(alink).removeClassName('nkfixed');
    	});
    	for(var i=0;i<self.columnModel.length;i++){
    		try{self.columnModel[i].fixed=false;}catch(e){}
    	}
    	//-----------重设-----------------------------------------
    	for(var i=0;i<self.syscells.length;i++){
    		$('nk_'+self.id+'_head_'+i).addClassName('nkfixed');
    	}
    	for(var i=0;i<=(index-self.syscells.length);i++){
    		var idx = self.syscells.length+i;
    		$('nk_'+self.id+'_head_'+idx).addClassName('nkfixed');
    		try{self.columnModel[i].fixed=true;}catch(e){}
    	}
    	self.initFexed();
    	self.initFxiedData();
    },
    //---------------获取列总宽度-------------------------------------
    cellsWidths : function(index){
    	var self = this;
    	var width = 0;
    	for(var i=0;i<self.syscells.length;i++){
    		width+=self.syscells[i].width;
    	}
    	for(var i=0;i<=(index-self.syscells.length);i++){
    		try{
    			width+=self.columnModel[i].width;
    		}catch(e){}
    	}
    	return width;
    },
    //---------------获取固定列的总列宽---------------------------------
    fexidCellsWidth : function(){
    	var self = this;
    	var fiexedWidth = 0;
    	var maxWidth = $('nk_'+self.id+'_data_div').getWidth();
    	$$('#nk_'+self.id+'_head_table th[class~="nkfixed"]').each(function(alink,index) {
    		if($(alink).visible()){
    			fiexedWidth+=$(alink).getWidth();
    		}
    	});
    	if(fiexedWidth>maxWidth){
    		fiexedWidth = maxWidth;
    	}
    	return fiexedWidth-1;
    },
    //---------------初始化固定列-------------------------------------
    initFexed : function(){
    	var self = this;
    	var fiexedBody = $('nk_'+self.id+'_left_head_div');
    	var fiexedWidth = self.fexidCellsWidth();
    	fiexedBody.setStyle({width:fiexedWidth+'px'});
    	self.sotpCellFxied();
    },
    //--------------初始化固定数据表--------------------------------------
    initFxiedData : function(){
    	var self = this;
    	var fiexedData = $('nk_'+self.id+'_left_data_div');
    	var tableData = $('nk_'+self.id+'_data_div');
    	var sumdiv = $('nk_'+self.id+'_fxied_sumcells_div');
    	var bsumdiv = $('nk_'+self.id+'_sumcells_div');
    	var tableBody = $('nk_'+self.id+'_data_table');
    	var doffset = tableBody.cumulativeOffset();
    	var fiexedWidth = self.fexidCellsWidth();
    	try{
    		fiexedData.hide();
    		if(tableData.scrollHeight>tableData.clientHeight){//有竖向滚动条
    			fiexedData.setStyle({width:fiexedWidth+'px',height:(tableData.clientHeight)+'px',top:(doffset.top+1)+'px',left:(doffset.left+1)+'px'});
    		}else{
    			fiexedData.setStyle({width:fiexedWidth+'px',height:(tableBody.offsetHeight)+'px',top:(doffset.top+1)+'px',left:(doffset.left+1)+'px'});
    		}
    		fiexedData.show();
    	}catch(e){}
    	try{
    		var boffset = bsumdiv.cumulativeOffset();
    		sumdiv.hide();
    		sumdiv.setStyle({width:fiexedWidth+'px',top:(boffset.top+1)+'px',left:(boffset.left+1)+'px'});
    		sumdiv.show();
    	}catch(e){}
    	self.sotpCellFxied();
    },
    //----------------禁用列固定功能-----------------------------------------
    sotpCellFxied : function(){
    	var self = this;
    	var syscells=self.syscells;
    	var ishide = true;
    	self.showFexDiv();
    	//-------------------------------------------------------------
    	for(var i=0;i<self.columnModel.length;i++){
    		if(self.columnModel[i].fixed && self.columnModel[i].show!=4){
    			ishide = false;//不禁用
    			break;
    		}
    	}
    	if(!self.fxeidcell){//未开启锁定列
    		self.hideFexDiv(true);
    	}
    	for(var i=0;i<syscells.length;i++){
    		if(syscells[i].type==1 || syscells[i].type==5){
    			self.hideFexDiv(true);
    			return;
    		}else if(syscells[i].show!=4){
    			ishide = false;
    		}
    	}
    	if(ishide){
    		self.hideFexDiv(false);
    	}
    },
    //----------显示--------------------------
    showFexDiv : function(){
    	var self = this;
    	var fiexedBody = $('nk_'+self.id+'_left_head_div');
    	var fiexedData = $('nk_'+self.id+'_left_data_div');
    	var sumdiv 	   = $('nk_'+self.id+'_fxied_sumcells_div'); 
    	try{fiexedBody.show();}catch(e){}
		try{fiexedData.show();}catch(e){}
		try{sumdiv.show();}catch(e){}
    },
    //----------隐藏-------------------------
    hideFexDiv : function(a){
    	var self = this;
    	var fiexedBody = $('nk_'+self.id+'_left_head_div');
    	var fiexedData = $('nk_'+self.id+'_left_data_div');
    	var sumdiv 	   = $('nk_'+self.id+'_fxied_sumcells_div'); 
    	if(a){
	    	$$('#nk_'+self.id+'_setmenu_table td[class~="fxeidsetmenu"]').each(function(alink,index) {
	    		$(alink).hide();
	    	});
    	}
		try{fiexedBody.hide();}catch(e){}
		try{fiexedData.hide();}catch(e){}
		try{sumdiv.hide();}catch(e){}
    },
    //-------------折行显示---------------------
    FxiedFoldingLine : function(){
    	var self = this;
    	self.initFxiedData();
    },
    //------------------------------------------------------------------
    insertInitBlankRow : function(){
    	var self = this;
    	if(self.insertBlankRowEnd>=self.insertBlankRow){
    		return;
    	}
    	for(var i=0;i<self.insertBlankRow;i++){
    		self.insertDataRow();//添加行
    		self.insertBlankRowEnd++;
    	}
    },
    //---------------清除---------------------------------------------
    selectMobdeEvent : function(){
    	var self = this;
    	if(undefined!=self.selectMode){
	    	$(self.id+'_select_clearvalue').observe('click',function(){
	    		$(self.selectMode).setValue('','');
	    	});
    	}
    },
    //------------外部初化事件---------------------------------
    userInit : function(){
    	var self = this;
    	try{
	    	if(undefined!=self.oninit){
	    		self.oninit(self);
	    	}
    	}catch(E){}//外部重设宽度
    },
    //------------隐藏表头和表底部-------------------------------
    hideHeadBottom : function(){
    	var self = this;
    	if(self.idHideHead){
    		$('nk_'+self.id+'_head_div').hide();
    	}
    	if(self.isHideBottom){
    		$('nk_'+self.id+'_bottom_div').hide();
    	}
    },
    //=================创建标题栏==============================
    CreateTitle : function(title){
    	var idx = 0;
        var html = [];
    	if(''!=title){
    		html[idx++]='<div style="width:'+this.width+'" class="nk_title_div" id="nk_'+this.id+'_title_div">';
    		html[idx++]='<table border="0"  cellpadding="0" cellspacing="0" style="width:'+this.width+'"  class="nk_title_table" id="nk_'+this.id+'_title_table">';
    		html[idx++]='<tr><td class="nk_title" id="nk_'+this.id+'_title_td">'+title+'</td></tr>';
    		html[idx++]='</table>';
    		html[idx++]='</div>';
    		return html.join('');
    	}
    	return '';
    },
    //==================拖动列宽的标位线=========================
    resizeMarkerLine : function(){
	    var self = this;
	    var idx = 0;
		var html = [];
		html[idx++]='<div id="resizeMarker_'+self.id+'_draag" style="z-index:99999">';
	    html[idx++]='<div id="resizeMarkerRight_'+self.id+'_draag" class="nk_resizeMarker" style="position: absolute;display: none;cursor: col-resize !important;cursor: w-resize;z-index:999999">&nbsp;</div>';
	    html[idx++]='<div id="resizeMarkerLeft_'+self.id+'_draag" class="nk_resizeMarker" style="position: absolute;display: none;cursor: col-resize !important;cursor: w-resize;z-index:999999">&nbsp;</div>';
	    html[idx++]='</div>';
	    return html.join('');
    },
    //==================创建列宽自动计算=========================
    CreateWidthTable : function(){
    	var idx = 0;
        var html = [];
        var self = this;
        var cells=self.columnModel;
        var syscells=self.syscells;
        if(self.autowidth){
	    	html[idx++]='<table border="0"  cellpadding="0" cellspacing="0" style="width:100%;"  id="nk_'+self.id+'_width_table">';
	    	html[idx++]='<tr>';
	    	for(var i=0;i<syscells.length;i++){
	    		if(syscells[i].show==1 || syscells[i].show==2){
	    			html[idx++]='<th  id="nk_'+self.id+'_htitle_td_'+i+'" width="'+syscells[i].width+'px" sytle="width:'+syscells[i].width+'px">&nbsp;</th>';
	    		}
	    	}
	    	for(var i=0;i<cells.length;i++){
	    		if(cells[i].show==1 || cells[i].show==2){
	    			html[idx++]='<th  id="nk_'+self.id+'_dtitle_td_'+i+'">&nbsp;</th>';
	    		}
	    	}
	    	html[idx++]='</tr>';
	    	html[idx++]='</table>';
	    	$('nk_'+self.id+'_size_width').innerHTML = html.join('');
	    	$$('th[id^="nk_'+self.id+'_htitle_td_"]').each(function(alink,index) {
	    		var idex = self.getRowIndex(alink);
	    		self.syscells[idex].width=$(alink).getWidth();
			});
	    	$$('th[id^="nk_'+self.id+'_dtitle_td_"]').each(function(alink,index) {
	    		var idex = self.getRowIndex(alink);
	    		try{
	    			self.columnModel[idex].width=$(alink).getWidth();
	    		}catch(e){
	    		}
	    	});
        }
    },
    //=================设置标题===============================
    setTitle : function(title){
    	$('nk_'+this.id+'_title_td').innerHTML=title;
    },
    //================创建表头================================
    CreateTableHead : function(){
    	var idx = 0;
        var html = [];
        var bidx = 0;
        var bhtml = [];
        var cells=this.columnModel;
        var syscells=this.syscells;
        var cellwidth=0;
        var hideWidth=0;
        var divtemp='<div id="{id}_div" width="{width}px" style="position:relative;width:{width}px;white-space:nowrap;text-overflow:ellipsis;-o-text-overflow:ellipsis;overflow:hidden;margin: 0;padding: 0;">';
        var ascimg ='<span><img id="nk_'+this.id+'_head_a_{i}_sequ" src="" title=""  alt="" style="display:none;" class="nk_asc_desc_images"></span>';
        var ascimg_show ='<span><img id="nk_'+this.id+'_head_a_{i}_sequ" src="{src}" title="{title}"  alt="{title}" style="" class="nk_asc_desc_images"></span>';
        var Lscimg ='<span><img id="nk_'+this.id+'_left_head_a_{i}_sequ" src="" title=""  alt="" style="display:none;" class="nk_asc_desc_images"></span>';
        var Lscimg_show ='<span><img id="nk_'+this.id+'_left_head_a_{i}_sequ" src="{src}" title="{title}"  alt="{title}" style="" class="nk_asc_desc_images"></span>';
        var divline='<div id="{id}"  style="position:relative;float:right;cursor:col-resize !important;cursor:w-resize;width:2px;z-index:30;">&nbsp;</div>';
        var hideInput='<input type="hidden" name="{name}" id="{id}" value="{value}">';//隐藏控件,列的name
        var hide = (this.showcell?"display: none;":"");
        var sysWidth = 0;
        bhtml[bidx++]='<div class="nk_head_div nk_fxeid_style" style="overflow:hidden;position:absolute;top:0px;left:0px;z-index:99;background:#fffff;width:{divwidth};'+hide+'" id="nk_'+this.id+'_left_head_div" width="{divwidth}">';
        html[idx++]  ='<div class="nk_head_div" style="overflow:hidden;width:{divwidth};'+hide+'"  width="{divwidth}" id="nk_'+this.id+'_head_div">';
        //---------------------------------------------------------------------------------------------------------
        html[idx++]='<table border="0" style="width:{width}px;" width="{width}px" cellpadding="0" cellspacing="0"  class="nk_head_table" id="nk_'+this.id+'_head_table">';
        bhtml[bidx++]='<table border="0" style="width:{width}px;" width="{width}px" cellpadding="0" cellspacing="0"  class="nk_head_table" id="nk_'+this.id+'_left_head_table">';
        html[idx++]='<thead>';
        html[idx++]='<tr>';
        bhtml[bidx++]='<thead>';
        bhtml[bidx++]='<tr>';
        //----------------------------------------------------------------------------------
        for(var i=0;i<syscells.length;i++){
        	var isShow=(syscells[i].show==1 || syscells[i].show==2)?"display:'';":"display:none;";
        	hideWidth+=(syscells[i].show==1 || syscells[i].show==2)?0:syscells[i].width;
        	var scwidth=syscells[i].width;
        	sysWidth = scwidth;
        	switch(syscells[i].type){//1 子表    2 序号  3 单选  4 多选    5 数据列
        	case 1://子表
         		html[idx++]='<th class="nk_head nkfixed" style="'+isShow+'width:'+syscells[i].width+'px;white-space:nowrap;position:relative;" width="'+syscells[i].width+'px" id="nk_'+this.id+'_head_'+i+'">';
         		bhtml[bidx++]='<th class="nk_head" style="'+isShow+'width:'+syscells[i].width+'px;white-space:nowrap;position:relative;" width="'+syscells[i].width+'px" id="nk_'+this.id+'_left_head_'+i+'">';
         		html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+this.id+'_head_'+i+'_div');
         		bhtml[bidx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+this.id+'_left_head_'+i+'_div');
         		html[idx++]=syscells[i].title+'</div></th>';
         		bhtml[bidx++]=syscells[i].title+'</div></th>';
        		break;
        	case 2://序号
        		html[idx++]='<th class="nk_head nkfixed" style="'+isShow+'width:'+syscells[i].width+'px;" width="'+syscells[i].width+'px" id="nk_'+this.id+'_head_'+i+'">';
        		bhtml[bidx++]='<th class="nk_head" style="'+isShow+'width:'+syscells[i].width+'px;" width="'+syscells[i].width+'px" id="nk_'+this.id+'_left_head_'+i+'">';
        		html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+this.id+'_head_'+i+'_div');
        		bhtml[bidx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+this.id+'_left_head_'+i+'_div');
        		html[idx++]=syscells[i].title+'</div></th>';
        		bhtml[bidx++]=syscells[i].title+'</div></th>';
        		break;
        	case 3://单选
        		html[idx++]='<th class="nk_head nkfixed" style="'+isShow+'width:'+syscells[i].width+'px;" width="'+syscells[i].width+'px" id="nk_'+this.id+'_head_'+i+'">';
        		bhtml[bidx++]='<th class="nk_head" style="'+isShow+'width:'+syscells[i].width+'px;" width="'+syscells[i].width+'px" id="nk_'+this.id+'_left_head_'+i+'">';
        		html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+this.id+'_head_'+i+'_div');
        		bhtml[bidx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+this.id+'_left_head_'+i+'_div');
        		html[idx++]='</div></th>';
        		bhtml[bidx++]='</div></th>';
        		break;
        	case 4://多项选择列
        		html[idx++]='<th class="nk_head nkfixed" style="'+isShow+'width:'+syscells[i].width+'px;" width="'+syscells[i].width+'px" id="nk_'+this.id+'_head_'+i+'">';
        		bhtml[bidx++]='<th class="nk_head" style="'+isShow+'width:'+syscells[i].width+'px;" width="'+syscells[i].width+'px" id="nk_'+this.id+'_left_head_'+i+'">';
        		html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+this.id+'_head_'+i+'_div');
        		bhtml[bidx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+this.id+'_left_head_'+i+'_div');
        		html[idx++]='<input type="checkbox" id="nk_'+this.id+'_check_all" class="nk_input_check"></input></div></th>';
        		bhtml[bidx++]='<input type="checkbox" id="nk_'+this.id+'_left_check_all" class="nk_input_check"></input></div></th>';
        		break;
        	case 5://树形表
         		html[idx++]='<th class="nk_head nkfixed" style="'+isShow+'width:'+syscells[i].width+'px;white-space:nowrap;position:relative;" width="'+syscells[i].width+'px" id="nk_'+this.id+'_head_'+i+'">';
         		bhtml[bidx++]='<th class="nk_head" style="'+isShow+'width:'+syscells[i].width+'px;white-space:nowrap;position:relative;" width="'+syscells[i].width+'px" id="nk_'+this.id+'_left_head_'+i+'">';
         		html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+this.id+'_head_'+i+'_div');
         		bhtml[bidx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+this.id+'_left_head_'+i+'_div');
         		html[idx++]=syscells[i].title+'</div></th>';
         		bhtml[bidx++]=syscells[i].title+'</div></th>';
        		break;
        	}
        	cellwidth+=syscells[i].width;
        }
        //----------------------------------------------------------------------------------
        for(var i=0;i<cells.length;i++){
        	var isShow=(cells[i].show==1 || cells[i].show==2)?"display:'';":"display:none;";
        	hideWidth+=(cells[i].show==1 || cells[i].show==2)?0:cells[i].width;
        	sysWidth+=(cells[i].fixed?cells[i].width:0);
        	var temp_ascimg=ascimg;
        	var Lemp_ascimg=Lscimg;
        	if(cells[i].name==this.options.pagedescorname){//
        		this.tempdescorascimg=this.initdescorascimg='nk_'+this.id+'_head_a_'+(i+syscells.length)+'_sequ';
        		this.tempdescorascimgFixed=this.initdescorascimg='nk_'+this.id+'_left_head_a_'+(i+syscells.length)+'_sequ';
        		var desc=this.getDescOrAscImg();
        		temp_ascimg=ascimg_show.replace(/\{src\}/g,desc.url).replace(/\{title\}/g, desc.title);
        		Lemp_ascimg=Lscimg_show.replace(/\{src\}/g,desc.url).replace(/\{title\}/g, desc.title);
        	}
        	var scwidth=cells[i].width;
        	html[idx++]='<th class="nk_head '+(cells[i].fixed?'nkfixed':'')+'" style="'+isShow+'width:'+cells[i].width+'px;border-collapse:collapse;" width="'+cells[i].width+'px" id="nk_'+this.id+'_head_'+(i+syscells.length)+'">';
        	bhtml[bidx++]='<th class="nk_head" style="'+isShow+'width:'+cells[i].width+'px;border-collapse:collapse;" width="'+cells[i].width+'px" id="nk_'+this.id+'_left_head_'+(i+syscells.length)+'">';
        	html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+this.id+'_head_'+(i+syscells.length)+'_div');
        	bhtml[bidx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+this.id+'_left_head_'+(i+syscells.length)+'_div');
        	html[idx++]='<div  style="float:left">';
        	bhtml[bidx++]='<div  style="float:left">';
        	html[idx++]=(undefined!=cells[i].prefix?cells[i].prefix:'');//列前缀
        	bhtml[bidx++]=(undefined!=cells[i].prefix?cells[i].prefix:'');//列前缀
        	html[idx++]='<a id="nk_'+this.id+'_head_a_'+(i+syscells.length)+'" href="javascript:void(0);" target="_self">'+cells[i].title+'</a>'+temp_ascimg.replace(/\{i\}/g, (i+syscells.length));
        	bhtml[bidx++]='<a id="nk_'+this.id+'_left_head_a_'+(i+syscells.length)+'" href="javascript:void(0);" target="_self">'+cells[i].title+'</a>'+Lemp_ascimg.replace(/\{i\}/g, (i+syscells.length));
        	html[idx++]=(undefined!=cells[i].suffix?cells[i].suffix:'');//列后缀
        	bhtml[bidx++]=(undefined!=cells[i].suffix?cells[i].suffix:'');//列后缀
        	html[idx++]='</div>';
        	bhtml[bidx++]='</div>';
        	html[idx++]= divline.replace(/\{id\}/g,'nk_'+this.id+'_head_drag_'+(i+syscells.length));
        	bhtml[bidx++]=divline.replace(/\{id\}/g,'nk_'+this.id+'_left_head_drag_'+(i+syscells.length));
        	html[idx++]='</div>';
        	bhtml[bidx++]='</div>';
        	html[idx++]=(undefined==cells[i].name?'':hideInput.replace(/\{name\}/g,'nk_'+this.id+'_head_a_'+(i+syscells.length)+'_name').replace(/\{id\}/g,'nk_'+this.id+'_head_a_'+(i+syscells.length)+'_name').replace(/\{value\}/g,cells[i].name));
        	bhtml[bidx++]=(undefined==cells[i].name?'':hideInput.replace(/\{name\}/g,'nk_'+this.id+'_left_head_a_'+(i+syscells.length)+'_name').replace(/\{id\}/g,'nk_'+this.id+'_left_head_a_'+(i+syscells.length)+'_name').replace(/\{value\}/g,cells[i].name));
        	html[idx++]='</th>';
        	bhtml[bidx++]='</th>';
        	cellwidth+=cells[i].width;
        	//---------------------------
        	if(undefined!=cells[i].sum && cells[i].sum){//需要汇总
        		this.sumcells=true;
        		this.sumcellidexs+=","+i;//需要自动汇总的列序号
        	}
        }
        this.bodyWidth=cellwidth-hideWidth;
        html[idx++]='<th  width="'+this.scrollBarWidth+'px" style="border-collapse:collapse;width:'+this.scrollBarWidth+'px;border-right:none;border-bottom:none;border-top:none;" class="nk_head" id="nk_'+this.id+'_head_'+(syscells.length+cells.length)+'">';
        bhtml[bidx++]='<th  width="'+this.scrollBarWidth+'px" style="border-collapse:collapse;width:'+this.scrollBarWidth+'px;border-right:none;border-bottom:none;border-top:none;" class="nk_head" id="nk_'+this.id+'_left_head_'+(syscells.length+cells.length)+'">';
        html[idx++]=divtemp.replace(/\{width\}/g,this.scrollBarWidth).replace(/\{id\}/g,'nk_'+this.id+'_head_'+(syscells.length+cells.length)+'_div');
        bhtml[bidx++]=divtemp.replace(/\{width\}/g,this.scrollBarWidth).replace(/\{id\}/g,'nk_'+this.id+'_left_head_'+(syscells.length+cells.length)+'_div');
        html[idx++]='</div></th>';
        bhtml[bidx++]='</div></th>';
        html[idx++]='</tr>';
        bhtml[bidx++]='</tr>';
        html[idx++]='</thead>';
        bhtml[bidx++]='</thead>';
        html[idx++]='</table>';
        bhtml[bidx++]='</table>';
        //-----------------------------------------------------------------------------
        html[idx++]='</div>';
        bhtml[bidx++]='</div>';
        return '<div style="position: relative">'+bhtml.join('').replace(/\{width\}/g,(this.bodyWidth+this.scrollBarWidth)).replace(/\{divwidth\}/g, sysWidth)+html.join('').replace(/\{width\}/g,(this.bodyWidth+this.scrollBarWidth)).replace(/\{divwidth\}/g, this.width)+'</div>';
    },
    //====================创建制定义统计列===================================================
    createSumcells : function(){
    	var idx = 0;
        var html = [];
        var fidx = 0;
        var fhtml =[];
        var self = this;
        var width = $('nk_'+self.id+'_head_div').getWidth();
        var cells=this.columnModel;
        var syscells=this.syscells;
        var cellwidth=0;
        var hideWidth=0;
        var divtemp='<div id="{id}_div" width="{width}px" style="position:relative;width:{width}px;white-space:nowrap;text-overflow:ellipsis;-o-text-overflow:ellipsis;overflow:hidden;margin: 0;padding: 0;">';
        if(self.sumcells){
	        html[idx++]='<div class="nk_sumcells_div"  id="nk_'+self.id+'_sumcells_div" style="width:'+width+'px;">';
	        html[idx++]='<table border="0" style="width:{width}px;" width="{width}px" cellpadding="0" cellspacing="0"  class="nk_sumcells_table" id="nk_'+self.id+'_sumcells_table">';
	        html[idx++]='<thead>';
	        html[idx++]='<tr>';
	        
	        fhtml[fidx++]='<div class="nk_sumcells_div nk_fxeid_style"  id="nk_'+self.id+'_fxied_sumcells_div" style="width:'+width+'px;position: fixed;z-index:99;">';
	        fhtml[fidx++]='<table border="0" style="width:{width}px;" width="{width}px" cellpadding="0" cellspacing="0"  class="nk_sumcells_table" id="nk_'+self.id+'_fxied_sumcells_table">';
	        fhtml[fidx++]='<thead>';
	        fhtml[fidx++]='<tr>';
	        //----------------------------------------------------------------------------------
	        for(var i=0;i<syscells.length;i++){
	        	var isShow=(syscells[i].show==1 || syscells[i].show==2)?"display:'';":"display:none;";
	        	hideWidth+=(syscells[i].show==1 || syscells[i].show==2)?0:syscells[i].width;
	        	var scwidth=syscells[i].width;
	        	switch(syscells[i].type){//1 子表    2 序号  3 单选  4 多选    5 数据列
	        	case 1://子表
	         		html[idx++]='<th class="nk_sumcells_th" style="'+isShow+'width:'+syscells[i].width+'px;white-space:nowrap;position:relative;" width="'+syscells[i].width+'px" id="nk_'+self.id+'_sumcells_'+i+'">';
	         		html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_sumcells_'+i+'_div');
	         		html[idx++]='&nbsp;</div></th>';
	         		
	         		fhtml[fidx++]='<th class="nk_sumcells_th" style="'+isShow+'width:'+syscells[i].width+'px;white-space:nowrap;position:relative;" width="'+syscells[i].width+'px" id="nk_'+self.id+'_fxied_sumcells_'+i+'">';
	         		fhtml[fidx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_fxied_sumcells_'+i+'_div');
	         		fhtml[fidx++]='&nbsp;</div></th>';
	        		break;
	        	case 2://序号
	        		html[idx++]='<th class="nk_sumcells_th" style="'+isShow+'width:'+syscells[i].width+'px;" width="'+syscells[i].width+'px" id="nk_'+self.id+'_head_'+i+'">';
	        		html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_sumcells_'+i+'_div');
	        		html[idx++]='&nbsp;</div></th>';
	        		
	        		fhtml[fidx++]='<th class="nk_sumcells_th" style="'+isShow+'width:'+syscells[i].width+'px;" width="'+syscells[i].width+'px" id="nk_'+self.id+'_fxied_head_'+i+'">';
	        		fhtml[fidx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_fxied_sumcells_'+i+'_div');
	        		fhtml[fidx++]='&nbsp;</div></th>';
	        		break;
	        	case 3://单选
	        		html[idx++]='<th class="nk_sumcells_th" style="'+isShow+'width:'+syscells[i].width+'px;" width="'+syscells[i].width+'px" id="nk_'+self.id+'_head_'+i+'">';
	        		html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_sumcells_'+i+'_div');
	        		html[idx++]='&nbsp;</div></th>';
	        		
	        		fhtml[fidx++]='<th class="nk_sumcells_th" style="'+isShow+'width:'+syscells[i].width+'px;" width="'+syscells[i].width+'px" id="nk_'+self.id+'_fxied_head_'+i+'">';
	        		fhtml[fidx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_fxied_sumcells_'+i+'_div');
	        		fhtml[fidx++]='&nbsp;</div></th>';
	        		break;
	        	case 4://多项选择列
	        		html[idx++]='<th class="nk_sumcells_th" style="'+isShow+'width:'+syscells[i].width+'px;" width="'+syscells[i].width+'px" id="nk_'+self.id+'_head_'+i+'">';
	        		html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_sumcells_'+i+'_div');
	        		html[idx++]='&nbsp;</div></th>';
	        		
	        		fhtml[fidx++]='<th class="nk_sumcells_th" style="'+isShow+'width:'+syscells[i].width+'px;" width="'+syscells[i].width+'px" id="nk_'+self.id+'_fxied_head_'+i+'">';
	        		fhtml[fidx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_fxied_sumcells_'+i+'_div');
	        		fhtml[fidx++]='&nbsp;</div></th>';
	        		break;
	        	case 5://多项选择列
	        		html[idx++]='<th class="nk_sumcells_th" style="'+isShow+'width:'+syscells[i].width+'px;" width="'+syscells[i].width+'px" id="nk_'+self.id+'_head_'+i+'">';
	        		html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_sumcells_'+i+'_div');
	        		html[idx++]='&nbsp;</div></th>';
	        		
	        		fhtml[fidx++]='<th class="nk_sumcells_th" style="'+isShow+'width:'+syscells[i].width+'px;" width="'+syscells[i].width+'px" id="nk_'+self.id+'_fxied_head_'+i+'">';
	        		fhtml[fidx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_fxied_sumcells_'+i+'_div');
	        		fhtml[fidx++]='&nbsp;</div></th>';
	        		break;
	        	}
	        	cellwidth+=syscells[i].width;
	        }
	        //----------------------------------------------------------------------------------
	        for(var i=0;i<cells.length;i++){
	        	var isShow=(cells[i].show==1 || cells[i].show==2)?"display:'';":"display:none;";
	        	hideWidth+=(cells[i].show==1 || cells[i].show==2)?0:cells[i].width;
	        	var scwidth=cells[i].width;
	        	html[idx++]='<th class="nk_sumcells_th" style="'+isShow+'width:'+cells[i].width+'px;border-collapse:collapse;" width="'+cells[i].width+'px" id="nk_'+self.id+'_sumcells_'+(i+syscells.length)+'">';
	        	html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_sumcells_'+(i+syscells.length)+'_div');
	        	html[idx++]='</div>';
	        	html[idx++]='</th>';
	        	
	        	fhtml[fidx++]='<th class="nk_sumcells_th" style="'+isShow+'width:'+cells[i].width+'px;border-collapse:collapse;" width="'+cells[i].width+'px" id="nk_'+self.id+'_fxied_sumcells_'+(i+syscells.length)+'">';
	        	fhtml[fidx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_fxied_sumcells_'+(i+syscells.length)+'_div');
	        	fhtml[fidx++]='</div>';
	        	fhtml[fidx++]='</th>';

	        	cellwidth+=cells[i].width;
	        }
	        this.bodyWidth=cellwidth-hideWidth;
	        html[idx++]='<th  width="'+self.scrollBarWidth+'px" style="border-collapse:collapse;width:'+self.scrollBarWidth+'px;border-right:none;border-bottom:none;border-top:none;" class="nk_sumcells_th" id="nk_'+self.id+'_sumcells_'+(syscells.length+cells.length)+'">';
	        html[idx++]=divtemp.replace(/\{width\}/g,this.scrollBarWidth).replace(/\{id\}/g,'nk_'+self.id+'_sumcells_'+(syscells.length+cells.length)+'_div');
	        html[idx++]='</div></th>';
	        html[idx++]='</tr>';
	        html[idx++]='</thead>';
	        html[idx++]='</table>';
	        html[idx++]='</div>';
	        
	        fhtml[fidx++]='<th  width="'+self.scrollBarWidth+'px" style="border-collapse:collapse;width:'+self.scrollBarWidth+'px;border-right:none;border-bottom:none;border-top:none;" class="nk_sumcells_th" id="nk_'+self.id+'_fxied_sumcells_'+(syscells.length+cells.length)+'">';
	        fhtml[fidx++]=divtemp.replace(/\{width\}/g,this.scrollBarWidth).replace(/\{id\}/g,'nk_'+self.id+'_fxied_sumcells_'+(syscells.length+cells.length)+'_div');
	        fhtml[fidx++]='</div></th>';
	        fhtml[fidx++]='</tr>';
	        fhtml[fidx++]='</thead>';
	        fhtml[fidx++]='</table>';
	        fhtml[fidx++]='</div>';
        }
        var fjoin = fhtml.join('').replace(/\{width\}/g,(this.bodyWidth+this.scrollBarWidth)).replace(/\{divwidth\}/g, this.width);
        return fjoin+html.join('').replace(/\{width\}/g,(this.bodyWidth+this.scrollBarWidth)).replace(/\{divwidth\}/g, this.width);
    },
    //====================设置汇总列的值==============================
    setSumValue : function(sumvalues){
    	var self = this;
    	$$('th[id^="nk_'+self.id+'_sumcells_"]').each(function(alink,index) {
    		try{
	    		var idex = self.getRowIndex(alink);
	    		var cellname = self.cellIndexToName(idex);//获取列名
	    		var value = sumvalues[cellname];
	    		if(undefined!=value){
	    			if(undefined!=self.onSetSumValue){
	    				value = self.onSetSumValue(cellname,value);
	    			}
	    			$(alink.id+'_div_div').innerHTML=value;
	    		}
    		}catch(e){}
		});
    	$$('th[id^="nk_'+self.id+'_fxied_sumcells_"]').each(function(alink,index) {
    		try{
	    		var idex = self.getRowIndex(alink);
	    		var cellname = self.cellIndexToName(idex);//获取列名
	    		var value = sumvalues[cellname];
	    		if(undefined!=value){
	    			if(undefined!=self.onSetSumValue){
	    				value = self.onSetSumValue(cellname,value);
	    			}
	    			$(alink.id+'_div_div').innerHTML=value;
	    		}
    		}catch(e){}
		});
    },
    //====================创建表体=================================
    CreateBody : function(){
    	var idx = 0;
        var html = [];
        var tableformname=(''==this.options.tableformname?this.id+'_dataformname':this.options.tableformname);
        var tableformid=(''==this.options.tableformid?this.id+'_dataformname':this.options.tableformid);
        this.options.tableformid=tableformid;
        var tableformAction=(''==this.options.tableformAction?'':this.options.tableformAction);
        var tableformtarget=(''==this.options.tableformtarget?'_self':this.options.tableformtarget);
        var tablemethod=(''==this.options.tablemethod?'post':this.options.tablemethod);
        var checks=(undefined==this.options.checks?'':this.options.checks);
        var checksv=(undefined==this.options.checksv?'':this.options.checksv);
        html[idx++]='<form style="margin:0px"  action="'+tableformAction+'" name="'+tableformname+'" id="'+tableformid+'" target="'+tableformtarget+'" method="'+tablemethod+'">';
        html[idx++]='<input type="hidden" id="'+this.options.checkrecord+'"	name="'+this.options.checkrecord+'"  value="'+checks+'"/>';
        html[idx++]='<input type="hidden" id="'+this.options.checkrecord+'_sv"	name="'+this.options.checkrecord+'_sv"  value="'+checksv+'"/>';
        html[idx++]='<input type="hidden" id="'+this.id+'"/>';
        html[idx++]='<input type="text" style="display: none;" id="'+this.id+'_entern"/>';
        html[idx++]='<input type="button" style="display:none;" id="nk_'+this.id+'_reLoadData"/>';
        html[idx++]='<input type="button" style="display:none;" id="nk_'+this.id+'_AjaxSubmitDataForm"/>';
        html[idx++]='<div style="width:{divwidth};height:'+this.heigth+';" class="nk_body_div"  id="nk_'+this.id+'_data_div">';
        html[idx++]='<table     border="0"  cellpadding="0" cellspacing="1"  class="nk_data_table" id="nk_'+this.id+'_data_table">';
        html[idx++]='<tr><td align="center" class="data_cell_0" >'+this.lanage.Lanage_loaddata+'</td></tr>';
        html[idx++]='</table>';
        html[idx++]='</div>';
        html[idx++]='</form>';
        return html.join('').replace(/\{divwidth\}/g, this.width);
    },
    //=====================组织查询参数============================
    GetPars : function(){
    	var self = this;
    	var pars=[];
    	var ix=0;
    	pars[ix++]='spage='+self.showpage;
    	if(''!=self.options.pagesize)
    		pars[ix++]='&pagesize='+self.options.pagesize;
    	if(''!=self.options.pagedescorname && ''!=self.options.pagedescorasc){
	    	pars[ix++]='&pagedescorname='+self.options.pagedescorname;
	    	pars[ix++]='&pagedescorasc='+self.options.pagedescorasc;
    	}
    	pars[ix++]='&sql='+self.sql;
    	if(undefined!=self.countsql){
    		pars[ix++]='&countsql='+self.countsql;
    	}
    	if(undefined!=self.treesql && self.sumsql=='treesql'){
    		pars[ix++]='&sumsql='+self.treesql;
    	}else{
    		pars[ix++]='&sumsql='+self.sql;
    	}
    	if(undefined!=self.cellname){
    		pars[ix++]='&cells='+encodeURIComponent(Object.toJSON(self.cellname));
    	}
    	if(self.options.onDataLoad!=undefined){
    		pars[ix++]='&onDataLoad='+self.options.onDataLoad;
    		pars[ix++]='&queryjson='+encodeURIComponent(self.getSelectValues().toJSON());
    	}
    	if(''!=self.options.formatcell){
    		pars[ix++]='&formatcell='+self.options.formatcell;
    	}
    	if(''!=self.options.sumformatcell){
    		pars[ix++]='&sumformatcell='+self.options.sumformatcell;
    	}
    	if(''!=self.options.dataclass)
    		pars[ix++]='&dataclass='+self.options.dataclass;
    	if('-1'!=self.sumcellidexs){
    		pars[ix++]='&sumcellidexs='+self.sumcellidexs;
    	}
    	pars[ix++]='&'+self.options.ajaxPrave;
    	//----------------查询条件------------------------------
    	if(''!=self.options.nkselect){
    		try{
    		$$('#'+self.options.nkselect+' input,select,textarea').each(function(alink,index) {
    			if(alink.type=='checkbox' || alink.type=='radio'){
        			if(alink.checked)
        				pars[ix++]='&'+alink.name+'='+alink.value;//alert(alink.name);
        		}else if(''!=alink.value){
        			pars[ix++]='&'+alink.name+'='+encodeURIComponent(alink.value);//alert(alink.name);
        		}
    		});
    		pars[ix++]='&sqlwhere='+self.options.selectfiled;
    		}catch(e){}
    	}
    	return pars.join('');
    },
    getSelectValues : function(){
    	var pars = [];
    	var idx = 0;
    	var self = this;
    	if(''!=self.options.nkselect){
    		try{
    		$$('#'+self.options.nkselect+' input,select,textarea').each(function(alink,index) {
    			if(alink.type=='checkbox' || alink.type=='radio'){
        			if(alink.checked){
        				pars[idx++]={name:alink.name,value:alink.value};
        			}
        		}else if(''!=alink.value){
        			pars[idx++]={name:alink.name,value:alink.value};
        		}
    		});
    		}catch(e){}
    	}
    	return pars;
    },
    //======================checkvalue==========================
    checkValueInit : function(){
    	var self = this;
    	var cells=this.columnModel;
    	var checkvalue = cells[0].name;
    	if(''==self.options.checkvalue || undefined == self.options.checkvalue){
    		checkvalue =cells[0].name;
    	}else if(!isNaN(self.options.checkvalue)){//数字
    		checkvalue =cells[parseInt(self.options.checkvalue)].name;
    	}else if(isNaN(self.options.checkvalue)){
    		checkvalue = self.options.checkvalue;
    	}
    	return checkvalue;
    },
    //=====================ajax加载数据============================
    LoadData : function(){
    	var dataBody=$('nk_'+this.id+'_data_div');
    	var self = this;
    	var cells=this.columnModel;
    	var syscells=this.syscells;
    	var isSubTable=false;
    	$('nk_'+this.id+'_load_dataing').show();//显示加载数据
    	var pars = self.GetPars();//获取查询参数
    	var jsonQuery = self.getSelectValues();
    	var lineHide=(self.foldingLine?'':'data_foldingline');//true 折行显示
    	var sysWidth = 0;
    	//------------------------------------------------------
    	new Ajax.Request(self.dataurl, {
            parameters: pars,
            method:'post',
            onSuccess: function(response) {
            	try{
	                var tableModel = response.responseText.evalJSON();
	                //----------------处理外部方法------------------------------
	            	if(!self.options.onloadjs(jsonQuery,tableModel)){//如果外部方法返回false，禁止加载 tableModel:options userData rows 
	            		$('nk_'+this.id+'_load_dataing').hide();
	            		return;
	            	}else if(tableModel.rows.length<1){
	                	self.LoadDataErro();
	                	self.rowNumber = 0;
	                }else{
		                var idx = 0;
		                var html = [];
		                var Ldx = 0;
		                var Ltml = [];
		                var divtemp='<div id="{id}_div" width="{width}px" class="'+lineHide+'" style="width:{width}px;margin: 0 atuo;padding: 0;">';
		                var selectValue = ','+$(self.options.checkrecord).value+',';//选择列
		                var textColor= (''==self.options.textColor?'#FFFFFF':self.options.textColor);
		            	var backgroundColor=(''==self.options.backgroundColor?'#09C':self.options.backgroundColor);
		            	var sumValue = [];//自动汇总列[{cell:'',value:''}]
		            	try{
			                if(undefined!=tableModel.options.sumcells){
			                	sumValue=tableModel.options.sumcells;
			                }
			            }catch(e){}
			            self.rowDatas = tableModel.rows;//保存数据
			            self.noData = false;
			            self.rowNumber=self.rowDatas.length;
		                if(self.showcell){//多列显示
		                	for(var i=0;i<tableModel.rows.length;i++){//行
		                		var row=tableModel.rows[i];
		                		var cellBody = $(self.id+'_cell_body_div').innerHTML;
		                		var checkvalue=self.checkValueInit();
			                	var checkname=(''==self.options.checkname?'nk_'+self.id+'_checkdata':self.options.checkname);
			                	var isSelect= selectValue.indexOf(','+row[checkvalue]+',')==-1?'':'checked="checked"';
			                	var isSelectStyle= selectValue.indexOf(','+row[checkvalue]+',')==-1?'':'color:'+textColor+';background-Color:'+backgroundColor;
		                		html[idx++] = '<div id="nk_'+self.id+'_dcell_'+i+'"  style="float: left;'+isSelectStyle+'" class="nk_user_cell_div">';
		                		for(var a=0;a<cells.length;a++){//列
		                			var a_n = '\\{'+a+'\\}';
		                			var a_s = '\\{'+cells[a].name+'\\}';
		                			try{
		                				cellBody = cellBody.replace(new RegExp(a_n,'g'),row[cells[a].name]);
		                			}catch(x){}
		                			try{
		                				cellBody = cellBody.replace(new RegExp(a_s,'g'),row[cells[a].name]);
		                			}catch(x){}
		                		}
		                		cellBody=cellBody.replace(/\{usercellid\}/g,'nk_'+self.id+'_dcell_'+i);//替换id
		                		cellBody=cellBody.replace(/\{row_no_id\}/g,i);//替换行序号变量
		                		cellBody=cellBody.replace(/\{row_id\}/g,'nk_'+self.id+'_dcell');//替换行id变量，不包含行序号
		                		html[idx++] = cellBody;
		                		html[idx++] = '<div id="nk_'+self.id+'_dcell_'+i+'_json" style="display: none;">'+Object.toJSON(row)+'</div>';
		                		if(self.options.checkd!=undefined && (self.options.checkd=='checkbox' || self.options.checkd=='radio')){
		                			html[idx++] = '<div><input type="'+self.options.checkd+'" '+isSelect+' name="'+checkname+'"  id="nk_'+self.id+'_dcell_'+i+'_checkbox" class="nk_input_check" value="'+row[checkvalue]+'" disabled="disabled"></div>';
		                		}else{
		                			html[idx++] = '<div style="display:none;"><input type="radio" '+isSelect+' name="'+checkname+'"  id="nk_'+self.id+'_dcell_'+i+'_checkbox" class="nk_input_check" value="'+row[checkvalue]+'" disabled="disabled"></div>';
		                		}
		                		html[idx++] = '</div>';
		                	}
		                	dataBody.innerHTML=html.join('');
			            	self.rowNumber = tableModel.rows.length;//总行数
			            	self.DataRowSelect();//加载行事件
			            	//--------------分页信息------------------------------------
			            	self.PageUtil($(self.id+'_buttom_data_page'),tableModel.options);
			            	$('nk_'+self.id+'_load_dataing').hide();//
		                }else{//常规表格
			                html[idx++] = '<table id="nk_'+self.id+'_data_table" border="0"  cellpadding="0" cellspacing="0"  class="nk_data_table">';
			                Ltml[Ldx++] = '<div id="nk_'+self.id+'_left_data_div" class="nk_fxeid_style" style="display:none;position:fixed;top:0px;left:0px;z-index:99;overflow:hidden;width:{divwidth}px;">';
			                Ltml[Ldx++] = '<table id="nk_'+self.id+'_left_data_table" border="0"  cellpadding="0" cellspacing="0"  class="nk_data_table">';
			                html[idx++] = '<tbody>';
			                Ltml[Ldx++] = '<tbody>';
			                
			                var selectValue = ','+$(self.options.checkrecord).value+',';//选择列
			                for(var i=0;i<tableModel.rows.length;i++){//行
			                	var row=tableModel.rows[i];//['aaa','vv']   | [{muid:'',meuusr:''}]
				                var classStyle=self.getAirLenClassStyle(cells,row, i);
				                html[idx++]='<tr id="nk_'+self.id+'_dcell_'+i+'">';
				                Ltml[Ldx++]='<tr id="nk_'+self.id+'_left_dcell_'+i+'">';
				                self.lastRowIdex = 'nk_'+self.id+'_dcell_'+i;
				                for(var a=0;a<syscells.length;a++){
				                	classStyle=self.getAirLenClassStyle(cells,row, i);
				                	var scwidth=syscells[a].width;//Prototype.Browser.WebKit
				                	var isShow=(syscells[a].show==1 || syscells[a].show==2)?"display:'';":"display:none;";
				                	var checkvalue=self.checkValueInit();
				                	var checkname=(''==self.options.checkname?'nk_'+self.id+'_checkdata':self.options.checkname);
				                	var isSelect= selectValue.indexOf(','+row[checkvalue]+',')==-1?'':'checked="checked"';
				                	sysWidth+=scwidth;
				                	switch(syscells[a].type){//1 子表    2 序号  3 单选  4 多选    5 数据列
				                    case 1://子表
				                    	html[idx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_dcell_'+a+'_'+i+'" width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
				                    	Ltml[Ldx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_left_dcell_'+a+'_'+i+'" width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
				                    	html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_dcell_'+a+'_'+i);
				                    	Ltml[Ldx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_left_dcell_'+a+'_'+i);
				                    	html[idx++]='<span><img  id="nk_'+self.id+'_dcell_subimage_'+a+'_'+i+'" src="'+self.url+'/tablegrid/images/plus_table.gif" title="" alt="" class="nk_sub_images"></span>';
				                    	Ltml[Ldx++]='<span><img  id="nk_'+self.id+'_left_dcell_subimage_'+a+'_'+i+'" src="'+self.url+'/tablegrid/images/plus_table.gif" title="" alt="" class="nk_sub_images"></span>';
				                    	html[idx++]='</div></td>';
				                    	Ltml[Ldx++]='</div></td>';
				                    	isSubTable=true;
				                 		break;
				                    case 2://序号
				                    	html[idx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_dcell_'+a+'_'+i+'" width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
				                    	Ltml[Ldx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_left_dcell_'+a+'_'+i+'" width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
				                    	html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_dcell_'+a+'_'+i);
				                    	Ltml[Ldx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_left_dcell_'+a+'_'+i);
				                    	html[idx++]=(i+1)+'</div></td>';
				                    	Ltml[Ldx++]=(i+1)+'</div></td>';
				                    	break;
				                    case 3://单选radio
				                    	html[idx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_dcell_'+a+'_'+i+'" width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
				                    	Ltml[Ldx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_left_dcell_'+a+'_'+i+'" width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
				                    	html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_dcell_'+a+'_'+i);
				                    	Ltml[Ldx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_left_dcell_'+a+'_'+i);
				                    	html[idx++]='<input type="radio" '+isSelect+' name="'+checkname+'" id="nk_'+self.id+'_dcell_'+a+'_'+i+'_checkbox" class="nk_input_check" value="'+row[checkvalue]+'"></input>';
				                    	Ltml[Ldx++]='<input type="radio" '+isSelect+' name="'+checkname+'_left" id="nk_'+self.id+'_left_dcell_'+a+'_'+i+'_checkbox" class="nk_input_check" value="'+row[checkvalue]+'"></input>';
				                    	html[idx++]='</div></td>';
				                    	Ltml[Ldx++]='</div></td>';
				                    	break;
				                    case 4://多项选择列
				                    	html[idx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_dcell_'+a+'_'+i+'" width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
				                    	Ltml[Ldx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_left_dcell_'+a+'_'+i+'" width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
				                    	html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_dcell_'+a+'_'+i);
				                    	Ltml[Ldx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_left_dcell_'+a+'_'+i);
				                    	html[idx++]='<input type="checkbox" '+isSelect+' name="'+checkname+'"  id="nk_'+self.id+'_dcell_'+a+'_'+i+'_checkbox" class="nk_input_check" value="'+row[checkvalue]+'"></input>';
				                    	Ltml[Ldx++]='<input type="checkbox" '+isSelect+' name="'+checkname+'"  id="nk_'+self.id+'_left_dcell_'+a+'_'+i+'_checkbox" class="nk_input_check" value="'+row[checkvalue]+'"></input>';
				                    	html[idx++]='</div></td>';
				                    	Ltml[Ldx++]='</div></td>';
				                    	$('nk_'+self.id+'_check_all').checked=false;
				                 		break;
				                    case 5://树形表
				                    	html[idx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_dcell_'+a+'_'+i+'" width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
				                    	Ltml[Ldx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_left_dcell_'+a+'_'+i+'" width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
				                    	html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_dcell_'+a+'_'+i);
				                    	Ltml[Ldx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_left_dcell_'+a+'_'+i);
				                    	html[idx++]='<span><img  id="nk_'+self.id+'_dcell_treeimage_'+a+'_'+i+'" src="'+self.url+'/tablegrid/images/plus_table.gif" title="" alt="" class="nk_sub_images"></span>';
				                    	Ltml[Ldx++]='<span><img  id="nk_'+self.id+'_left_dcell_treeimage_'+a+'_'+i+'" src="'+self.url+'/tablegrid/images/plus_table.gif" title="" alt="" class="nk_sub_images"></span>';
				                    	html[idx++]='</div></td>';
				                    	Ltml[Ldx++]='</div></td>';
				                 		break;
				                	}
				                }
				                for(var a=0;a<cells.length;a++){//列
				                	classStyle=self.getAirLenClassStyle(cells,row, i);
				                	//----------------------------------------------------------------------------
				                	var isShow=(cells[a].show==1 || cells[a].show==2)?"display:'';":"display:none;";
				                	//----------------------------------------------------------------------------
				                	sysWidth+=(cells[a].fixed?cells[a].width:0);
				                	//-----------------单元格警示样式--------------------------------------------------
				                	if(undefined!=cells[a].aircell){
					                	for(var s=0;s<cells[a].aircell.length;s++){
					                		if(row[cells[a].name]==cells[a].aircell[s].key){
					                			classStyle=cells[a].aircell[s].cl;
					                			break;
					                		};
					                	};
				                	}
				                	//-----------------编辑单元格样式---------------------------------------------------
				                	if(undefined!=self.editCells){
				                		for(var s=0;s<self.editCells.length;s++){
				                			if(cells[a].name == self.editCells[s].cell){
				                				classStyle='data_cell_edit';
				                				break;
				                			}
				                		}
				                	}
				                	var dataValue=row[cells[a].name];
				                	var dcwidt=cells[a].width;
				                	if(undefined!=cells[a].dfmt){
				                		dataValue = self.formdates(dataValue,cells[a].dfmt);//格化时间
				                	}
				                	if(undefined!=cells[a].fmt){
				                		try{
				                			dataValue = cells[a].fmt(dataValue,row);//自定义格式化
				                		}catch(e){}
				                	}
				                    html[idx++]='<td width="'+cells[a].width+'" style="'+isShow+'width:'+cells[a].width+'px;" class="'+classStyle+'"  id="nk_'+self.id+'_dcell_'+(a+syscells.length)+'_'+i+'" >';
				                    Ltml[Ldx++]='<td width="'+cells[a].width+'" style="'+isShow+'width:'+cells[a].width+'px;" class="'+classStyle+'"  id="nk_'+self.id+'_left_dcell_'+(a+syscells.length)+'_'+i+'" >';
				                    html[idx++]=divtemp.replace(/\{width\}/g,(dcwidt)).replace(/\{id\}/g,'nk_'+self.id+'_dcell_'+(a+syscells.length)+'_'+i);
				                    Ltml[Ldx++]=divtemp.replace(/\{width\}/g,(dcwidt)).replace(/\{id\}/g,'nk_'+self.id+'_left_dcell_'+(a+syscells.length)+'_'+i);
				                    html[idx++]=dataValue+'</div>';
				                    Ltml[Ldx++]=dataValue+'</div>';
				                    html[idx++]=self.initEditJSONHiedInput((a+syscells.length),i,dataValue); 
				                    Ltml[Ldx++]=self.initEditJSONHiedInput((a+syscells.length),i,dataValue); 
				                    //-------------------------------------------------------------------------
				                    html[idx++]='</td>';
				                    Ltml[Ldx++]='</td>';
				                }
				                html[idx++]='</tr>';
				                Ltml[Ldx++]='</tr>';
				                if(isSubTable)//子表
				                    html[idx++]=self.CreateSubTable(i, row);
				                }
			                html[idx++] = '</tbody>';
			                Ltml[Ldx++]='</tbody>';
			                html[idx++]='</table>';
			                Ltml[Ldx++]='</table>';
			                Ltml[Ldx++]='</div>';
			                
			                var fxiedHtml = Ltml.join('').replace(/\{width\}/g,(self.GetDataBodyWidth())).replace(/\{divwidth\}/g,sysWidth);
			            	dataBody.innerHTML=fxiedHtml+html.join('').replace(/\{width\}/g,(self.GetDataBodyWidth()));
			            	self.rowNumber = $('nk_'+self.id+'_data_table').rows.length;//总行数
			            	self.DataRowSelect();//加载行事件
			            	if(isSubTable){//子表
			            		self.SubTableUtil();//加载子表事件
			            	}
			            	if(undefined!=self.treesql){
			            		self.TreeTableUtil();
			            	}
			            	//--------------分页信息------------------------------------
			            	self.PageUtil($(self.id+'_buttom_data_page'),tableModel.options);
			            	$('nk_'+self.id+'_load_dataing').hide();//
			            	//-----------------------------------------------------------
			            	self.setSumValue(sumValue);//设置统计列的值
			            	//--------------行高---------------------------------------
			            	try{
			            		self.rowHeight = $('nk_'+self.id+'_dcell_0_0').getHeight();
			            	}catch(e){}
			            	//------------------------------------------------------
			            	setTimeout(function(){
			            		self.initEditValue();
			            	},10);
		                }
	                }
	            	try{
	            		$('nk_'+self.id+'_left_data_div').scrollTop=0;
	            		$('nk_'+self.id+'_data_div').scrollTop=0;
	            	}catch(e){}
	            	self.options.onend(jsonQuery,tableModel);
	            	self.resize();
            	}catch(e){
            		self.LoadDataErro();
            	}
            },
        //---------------------失败-----------------------------------------
    	onFailure : function(transport) {
    		self.LoadDataErro();
        }
    	});
    },
    //--------------------------警示行样式-----------------------------------
    getAirLenClassStyle : function(cells,row,rowindex){
    	var classStyle = "";
    	try{
	    	classStyle = (rowindex%2==0?"data_cell_0":"data_cell_1");
	    	if(undefined!=cells){
	    		for(var a=0;a<cells.length;a++){
			    	if(undefined!=cells[a].airlencell){
			        	for(var s=0;s<cells[a].airlencell.length;s++){
			        		if(row[cells[a].name]==cells[a].airlencell[s].key){
			        			return cells[a].airlencell[s].cl;
			        		};
			        	};
			    	}
	    		}
	    	}
    	}catch(e){}
    	return classStyle;
    },
    //--------------------------获取数据表体宽度-------------------------------
    GetDataBodyWidth : function(){
    	var self = this;
    	var headTable=$('nk_'+self.id+'_head_table');//表头对像
        var tableWidth=parseInt(headTable.getWidth())-self.scrollBarWidth;//self.cellwidth;//
        return tableWidth;
    },
    //===========================加载错误信息===========================
    LoadDataErro : function(){
    	var tableModel=Class.create({
			options:{
    			pagecont:0,
    			showpage:0,
    			startrow:0,
    			endrow:0,
    			pagesize:0,
    			lastRow:0
			}
		});
    	var self = this;
    	var dataBody=$('nk_'+self.id+'_data_div');
		var idx = 0;
        var html = [];
        self.noData = true;//没有数据
		html[idx++]='<table id="nk_'+self.id+'_data_table" style="width:{width}px" border="0"  cellpadding="0" cellspacing="0">';
        html[idx++] = '<tbody>';
        html[idx++]='<tr><td align="center" class="data_cell_0" style="width:{width}px" id="nk_'+self.id+'_dcell_0_0">'+self.lanage.Lanage_nodainfo+'</td></tr>';
        html[idx++] = '</tbody>';
        html[idx++]='</table>';
        dataBody.innerHTML=html.join('').replace(/\{width\}/g, (self.GetDataBodyWidth()));
        $('nk_'+self.id+'_load_dataing').hide();//
        try{
    		self.rowHeight = $('nk_'+self.id+'_dcell_0_0').getHeight();
    	}catch(e){}
    	self.PageUtil($(self.id+'_buttom_data_page'),tableModel.options);
    	self.resize();
    },
    //======================自动刷新=======================================
    TimeAutoRefresh : function(){
    	var self = this;
    	if(self.options.autoRefresh>0){//自动刷新时间大于0
    		var sleepre = self.options.autoRefresh*1000;//以秒为单位
    		self.AutoRefresh();//自动刷新操作
	    	setTimeout(function() {//自动刷新
	            	 self.TimeAutoRefresh();
	        }, sleepre);
    	}
    },
    AutoRefresh : function(){
    	var self = this;
    	var pars = self.GetPars();//获取查询参数
    	new Ajax.Request(self.dataurl, {
            parameters: pars,
            method:'post',
            onSuccess: function(response) {
            	try{
	                var tableModel = response.responseText.evalJSON();
	                if(self.LastRown!=tableModel.options.lastRow){//总记录改变,耍新
	                	self.LastRown=tableModel.options.lastRow;
	                	$('nk_'+self.id+'_reLoadData').click();//刷新数据
	                }
            	}catch(e){
            	}
            }
    	});
    },
    //======================创建子表=======================================
    CreateSubTable : function(index,cell){//行号,列对像
    	var colspan=(this.syscells.length+Object.keys(cell).length);
    	var idx = 0;//_sub_style_div
        var html = [];
        html[idx++]='<tr id="nk_'+this.id+'_subcell_'+index+'" style="display:none;">';
        html[idx++]='<td id="nk_'+this.id+'_subcell_'+index+'_td" class="nk_sub_td" colspan="'+colspan+'"></td>';
        html[idx++]='</tr>';
        return html.join('');
    },
    //=======================加载子表数据==================================
    SubTableLoad : function(index,row,td){
    	var subTable=this.subTable;
        var cells=this.columnModel;
        var syscells=this.syscells;//附加列
    	//-----------------表列-------------------------------------------
        if("cell"==subTable.subtabletype){//列对像
        	try{
	        	var body=$(this.id+'_sub_style_div').innerHTML;
	        	for(var i=parseInt(syscells.length);i<row.cells.length;i++){
	        		var reg=new RegExp("\\$\\{"+(i-parseInt(syscells.length))+"\\}","g");
	        		body=body.replace(reg, row.cells[i].innerHTML);
	        	}
	        	td.innerHTML=body;
        	}catch(e){
        		var indexs = subTable.subtable.split(','); //a,b,c
        		for(var i=0;i<indexs.length;i++){
        			var ceindex=parseInt(indexs[i]);
        			var vcell=(parseInt(syscells.length)+ceindex);
        			td.innerHTML+='<br>'+cells[ceindex].title+':'+row.cells[vcell].innerHTML+'</br>';
        		}
        	}
        }
        //----------------sql--------------------------------------------
        if("sql"==subTable.subtabletype){//列对像
        	var idx = 0;//
        	var parsv=[];
        	parsv[idx++]='do=sql';
        	parsv[idx++]='&noka_subsql='+subTable.subtable;
        	parsv[idx++]=((subTable.subformatcell=='')?'':'&noka_subformatcell='+subTable.subformatcell);
        	if(subTable.subtablestyleid!=''){
        		//-------------默认参数-----------------------------------------
        		var indexs = subTable.subtablestyleid.split(','); //2,3,5
        		for(var i=0;i<indexs.length;i++){
        			var vstr = indexs[i];
        			if(isNaN(vstr)){//非数字
        				try{
	        				var vell = $(vstr).value;
	        				if(undefined!=vell && vell.trim().length>0){
	        					parsv[idx++]='&noka_subsqlwhere='+vell;
	        				}
        				}catch(a){}
        			}else{
        				try{
	        				var ceindex=parseInt(indexs[i]);
	        				var vcell=(parseInt(syscells.length)+ceindex);
	        				var vell=$(row.cells[vcell].id+'_div').innerHTML;
	        				parsv[idx++]=((vell=='')?'':'&noka_subsqlwhere='+vell);
        				}catch(e){}
        			}
        		}
        		//--------------外部方法---------------------------------------
        		if(undefined!=subTable.onloadsubtable){
        			var cvalue = subTable.onloadsubtable(row);
        			if(undefined!=cvalue){//[{name:'',value:''}]
        				for(var i=0;i<cvalue.length;i++){
        					try{
	        					if(undefined!=cvalue[i].name && undefined!=cvalue[i].value && cvalue[i].value.trim().length>0){
	        						parsv[idx++]='&'+cvalue[i].name+'='+cvalue[i].value;
	        					}
        					}catch(e){}
        				}
        			}
        		}
        	}
        	new Ajax.Request(this.subtableurl, {
        		method:'post',
                parameters: parsv.join(''),
                onSuccess: function(response) {
                	td.innerHTML= response.responseText;
                }
        	});
        }
        //----------------class------------------------------------------
        if("class"==subTable.subtabletype){
        	var idx = 0;//
        	var parsv=[];
        	parsv[idx++]='do=cl';
        	for(var i=parseInt(syscells.length);i<row.cells.length;i++){
        		parsv[idx++]='&noka_sub_data='+row.cells[i].innerHTML;//行数据
        	}
        	for(var i=0;i<cells.length;i++){
        		parsv[idx++]='&noka_sub_cell='+cells[i].title;//列名
        	}
        	parsv[idx++]='&noka_sub_subtable='+subTable.subtable;//类名
        	parsv[idx++]='&noka_sub_i='+index;//行号
        	new Ajax.Request(this.subtableurl, {
        		method:'post',
                parameters: parsv.join(''),
                onSuccess: function(response) {
                	td.innerHTML= response.responseText;
                }
        	});
        }
    },
    //=====================自定义统计栏===================================
    CreateCustom : function(){
    	var idx = 0;
        var html = [];
        if(''!=this.options.custom){
        html[idx++]='<div class="nk_custom_div"  id="nk_'+this.id+'_custom_div">';
        html[idx++]=this.options.custom;
        html[idx++]='</div>';
        }
        return html.join('');
    },
    //=====================设置自定义栏内容=================================
    SetCustom : function(value){
    	$('nk_'+this.id+'_custom_div').innerHTML=value;
    },
    //=======================创建底部菜单==================================
    Createbottom : function(){
    	var idx = 0;
        var html = [];
        var minstyle = (this.minpage?'style="display:none;"':'');//迷你分页模式
        html[idx++]='<div class="nk_bottom_div"  id="nk_'+this.id+'_bottom_div">';
        html[idx++]='<table width="100%"  border="0"  cellpadding="0" cellspacing="0"  class="nk_bottom_table" id="nk_'+this.id+'_bottom_table">';
        html[idx++]='<tr>';
        html[idx++]='<td class="nk_page_cell_1" id="'+this.id+'_buttom_user">'+this.options.custombutton;
        if(undefined!=this.selectMode){//下拉模式下自动生成清除值按钮
        	html[idx++] = '<input type="button" class="select_button" value="'+this.lanage.Lanage_SelectClear+'" name="'+this.id+'_select_clearvalue" id="'+this.id+'_select_clearvalue"/>';
        }
        if(this.options.editRow!=undefined){//开启行编辑
        	if(this.options.editRow.addEdit)
        		html[idx++]='<input type="button" class="select_button" id="nk_'+this.id+'_button_insert_row" value="'+this.lanage.Lanage_addRow+'"/>';
        	if(this.options.editRow.delEdit)
        		html[idx++]='<input type="button" class="select_button" id="nk_'+this.id+'_button_del_row" value="'+this.lanage.Lanage_delRow+'"/>';
        }
        if(this.editAllSubmitAction){//开启一次性提交
        	html[idx++]='<input type="button" class="select_button" id="nk_'+this.id+'_button_eidt_submit_all" value="'+this.lanage.Lanage_EditSubmit+'"/>';
        }
        html[idx++]='</td>';
        html[idx++]='<td class="nk_page_cell_1" align="right"><table border="0"  cellpadding="0" cellspacing="0"><tr>';
        html[idx++]='<td class="nk_page_cell_1" align="right">';
        html[idx++]='<img style="display:none;" class="noka_grid_page_img" src="'+this.url+'/tablegrid/images/mtg-loader.gif" id="nk_'+this.id+'_load_dataing"/>';
        if(''!=this.options.reload){
        	html[idx++]='<img class="noka_grid_page_img" src="'+this.url+'/tablegrid/images/refresh.png" id="nk_'+this.id+'_reload_img" title="'+this.lanage.Lanage_reload+'" alt="'+this.lanage.Lanage_reload+'" />';
        }
        //-------------------excel---------------------------------------
        if(''!=this.options.outexcelnopage){
        	html[idx++]='<img class="noka_grid_page_img" src="'+this.url+'/tablegrid/images/tool_xls.gif" id="nk_'+this.id+'_outexcel_page" title="'+this.lanage.Lanage_outexcelPage+'" alt="'+this.lanage.Lanage_outexcelPage+'"/>';
        }
        if(''!=this.options.outexcelall){
        	html[idx++]='<img class="noka_grid_page_img" src="'+this.url+'/tablegrid/images/tool_xls2.gif" id="nk_'+this.id+'_outexcel_alldata" title="'+this.lanage.Lanage_outexcelAll+'" alt="'+this.lanage.Lanage_outexcelAll+'"/>';
        }
        //-----------------csv------------------------------------------
        if(''!=this.options.outcsvnopage){
        	html[idx++]='<img class="noka_grid_page_img" src="'+this.url+'/tablegrid/images/csv1.gif" id="nk_'+this.id+'_outcsv_page" title="'+this.lanage.Lanage_outcsvPage+'" alt="'+this.lanage.Lanage_outcsvPage+'"/>';
        }
        if(''!=this.options.outcsvall){
        	html[idx++]='<img class="noka_grid_page_img" src="'+this.url+'/tablegrid/images/csv2.gif" id="nk_'+this.id+'_outcsv_alldata" title="'+this.lanage.Lanage_outcsvAll+'" alt="'+this.lanage.Lanage_outcsvAll+'"/>';
        }
        //----------------pdf-------------------------------------------
        if(''!=this.options.outpdfnopage){
        	html[idx++]='<img class="noka_grid_page_img" src="'+this.url+'/tablegrid/images/pdf.gif" id="nk_'+this.id+'_outpdf_page" title="'+this.lanage.Lanage_outpdfPage+'" alt="'+this.lanage.Lanage_outpdfPage+'" />';
        }
        if(''!=this.options.outpdfall){
        	html[idx++]='<img class="noka_grid_page_img" src="'+this.url+'/tablegrid/images/pdf2.gif" id="nk_'+this.id+'_outpdf_alldata" title="'+this.lanage.Lanage_outpdfAll+'" alt="'+this.lanage.Lanage_outpdfAll+'" />';
        }
        if(this.setkey){
        	  html[idx++]='<img class="noka_grid_page_img"  src="'+this.url+'/tablegrid/images/icon-grid.gif" id="nk_'+this.id+'_clearsetButton" title="'+this.lanage.Lanage_clearButton+'" alt="'+this.lanage.Lanage_clearButton+'" />';
        }else{
        	  html[idx++]='<img class="noka_grid_page_img" style="display: none;" src="'+this.url+'/tablegrid/images/icon-grid.gif" id="nk_'+this.id+'_clearsetButton" title="'+this.lanage.Lanage_clearButton+'" alt="'+this.lanage.Lanage_clearButton+'" />';
        }
        //---------------清除列设置-----------------------------------------
        if(undefined !=this.flodingButton && !this.showcell){
        	html[idx++]='<img class="noka_grid_page_img" '+minstyle+' src="'+this.url+'/tablegrid/images/zhexingactive.png" id="nk_'+this.id+'_flodingButton" title="'+this.lanage.Lanage_flodingButton+'" alt="'+this.lanage.Lanage_flodingButton+'" />';
        }else{
         	html[idx++]='<img class="noka_grid_page_img" style="display: none;"  src="'+this.url+'/tablegrid/images/zhexingactive.png" id="nk_'+this.id+'_flodingButton" title="'+this.lanage.Lanage_flodingButton+'" alt="'+this.lanage.Lanage_flodingButton+'" />';
        }
        if(!this.showcell){
        	html[idx++]='<img class="noka_grid_page_img" '+minstyle+' src="'+this.url+'/tablegrid/images/settings.gif" id="nk_'+this.id+'_setimage" title="'+this.lanage.Lanage_setimagell+'" alt="'+this.lanage.Lanage_setimagell+'" />';
        }else{//自定义单元格时，隐藏列设置按钮
        	html[idx++]='<img class="noka_grid_page_img" style="display:none;" src="'+this.url+'/tablegrid/images/settings.gif" id="nk_'+this.id+'_setimage" title="'+this.lanage.Lanage_setimagell+'" alt="'+this.lanage.Lanage_setimagell+'" />';
        }
        html[idx++]='</td>';
        html[idx++]='<td class="nk_page_cell_1" align="right" id="'+this.id+'_buttom_data_page"></td>';//分页信息
        html[idx++]='</tr></table><td><tr>';
        html[idx++]='</table>';
        html[idx++]='</div>';
        html[idx++]='<div id="nk_'+this.id+'_outexcel_form_div" style="display:none;width:0px; height:0px;"></div>';
        return html.join('');
    },
    //=======================分页信息======================================
    PageUtil : function(pageObject,pageOptions){
    	var idx = 0;
        var html = [];
        var self=this;
        var pageInfo='<a  class="noka_grid_page_number">'+self.lanage.Lanage_PageInfo+'</a>';
        //-------------------分页信息显示----------------------------------
        var last = 0;
		var preten =0;
		var lastten =0;
		var pagecont=0;
		var pagecode = self.pagecode;
		var minstyle = self.minpage?'style="display:none;"':'';
        var firstPage ='<a title="'+self.lanage.Lanage_firstImg+'" id="'+self.id+'_page_fst_img" '+minstyle+' class="noka_grid_page_number">&#60&#60</a>';
        var TopPage	  ='<a title="'+self.lanage.Lanage_topImg+'" id="'+self.id+'_page_top_img"  class="noka_grid_page_number">&#60</a>';
        var AfterPage ='<a title="'+self.lanage.Lanage_aftImg+'" id="'+self.id+'_page_aft_img" class="noka_grid_page_number">&#62</a>';
        var endPage	 ='<a title="'+self.lanage.Lanage_endImg+'" id="'+self.id+'_page_end_img" '+minstyle+' class="noka_grid_page_number">&#62&#62</a>';
        try{
	        var showPage =pageOptions.showpage;//当前显示页
	        pagecont=pageOptions.pagecont;//总页数
	        var spare=(showPage / pagecode)|0;
	        var pre = ((spare <1) ? 1 : spare * pagecode+1);
	        pre=(pre>pagecont?spare:pre);
			last = (pagecont > pre + (pagecode-1)) ? (pre + (pagecode-1)) : pagecont;
			preten = (pre > pagecode) ? (pre - pagecode) : 1;
			lastten = (pagecont >= pre + pagecode) ? (pre + pagecode) : last;
			html[idx++]=firstPage+TopPage;
			for (var i = pre; i <= last; i++){
				if (i == showPage)
					html[idx++]='<a class="noka_grid_page_number_select">' + i +'</a>';
				else
					html[idx++]='<a class="noka_grid_page_number" id="nk_'+self.id+'_page_a_'+i+'" alt="'+self.lanage.Lanage_pageAlink.replace(/\{i\}/g, i)+'" title="'+self.lanage.Lanage_pageAlink.replace(/\{i\}/g, i)+'" href="javascript:void(0);" target="_self">'+i+'</a>';
			}
			html[idx++]=AfterPage+endPage;
			if(!self.minpage){//迷你分页模式
				pageInfo=pageInfo.replace(/\{showPage\}/g,showPage);
				pageInfo=pageInfo.replace(/\{pageConut\}/g,pagecont);
				pageInfo=pageInfo.replace(/\{newpagesize\}/g,pageOptions.pagesize);
				pageInfo=pageInfo.replace(/\{newpagestartnumber\}/g,pageOptions.startrow);
				pageInfo=pageInfo.replace(/\{newpagesendnumber\}/g,pageOptions.endrow);
				pageInfo=pageInfo.replace(/\{lastRow\}/g,pageOptions.lastRow);
				html[idx++]=pageInfo;
			}
        }catch(e){
        	html[idx++]=firstPage+TopPage;
        	html[idx++]=AfterPage+endPage;
        	if(!self.minpage){//迷你分页模式
	        	pageInfo=pageInfo.replace(/\{showPage\}/g,0);
	        	pageInfo=pageInfo.replace(/\{pageConut\}/g,0);
				pageInfo=pageInfo.replace(/\{newpagesize\}/g,0);
				pageInfo=pageInfo.replace(/\{newpagestartnumber\}/g,0);
				pageInfo=pageInfo.replace(/\{newpagesendnumber\}/g,0);
				pageInfo=pageInfo.replace(/\{lastRow\}/g,0);
				html[idx++]=pageInfo;
        	}
        }
		pageObject.innerHTML=html.join('');
		if(''!=self.options.pagesize){//有分页
			//----------------分页事件-----------------------------------------
			$$('a[id^="nk_'+self.id+'_page_a_"]').each(function(alink,index) {
	            $(alink).observe('click', function() {
	            	self.showpage=$(alink).innerHTML;//当前页
	            	self.LoadData();
	            });
	        });
			$(self.id+'_page_fst_img').observe('click', function() {
	        	self.showpage=1;//第一页
	        	self.LoadData();
	        });
			$(self.id+'_page_top_img').observe('click', function() {
	        	self.showpage=preten;//上10页
	        	self.LoadData();
	        });
			$(self.id+'_page_aft_img').observe('click', function() {
	        	self.showpage=lastten;//下10页
	        	self.LoadData();
	        });
			$(self.id+'_page_end_img').observe('click', function() {
	        	self.showpage=pagecont;//最后一页
	        	self.LoadData();
	        });
			$$('a.noka_grid_page_number').each(function(alink,index) {
	    		$(alink).observe('mousemove', function() {
	             	$(alink).removeClassName('noka_grid_page_number');
	             	$(alink).addClassName('noka_grid_page_number_hover');
	             });
	             $(alink).observe('mouseout', function() {
	             	$(alink).removeClassName('noka_grid_page_number_hover');
	             	$(alink).addClassName('noka_grid_page_number');
	             });
	    	});
		}else{
			pageObject.hide();
		}
    },
    //==============================================================
    setPageStyle : function(){
    	$$('img.noka_grid_page_img').each(function(alink,index) {
    		$(alink).observe('mousemove', function() {
             	$(alink).removeClassName('noka_grid_page_img');
             	$(alink).addClassName('noka_grid_page_img_hover');
             });
             $(alink).observe('mouseout', function() {
             	$(alink).removeClassName('noka_grid_page_img_hover');
             	$(alink).addClassName('noka_grid_page_img');
             });
    	});
    },
    //=======================创建设置列显示/隐藏菜单========================
    CreateSetMenu : function(){
    	var idx = 0;
        var html = [];
        var cells=this.columnModel;
        var syscells=this.syscells;
        var textColor= '';//(''==this.options.textColor?'#FFFFFF':this.options.textColor);
    	var backgroundColor='';//(''==this.options.backgroundColor?'#09C':this.options.backgroundColor);
        html[idx++]='<div style="padding-right:0px;top:0px;left:0px;width:{width}px;height:{height}px;display:none;position: absolute;" width="{width}px" height="{height}px" class="nk_cell_menu" id="nk_'+this.id+'_setmenu_div">';
        html[idx++]='<table style="width:{twidth}px;" width="{twidth}px"   border="0"  cellpadding="0" cellspacing="0"  class="nk_table_menu" id="nk_'+this.id+'_setmenu_table">';
        var cwidth=0;
        var height=0;
        //-----------------标题行---------------------------------------------------------------------------------------------------------
        html[idx++]='<tr style="cursor:default" id="nk_'+this.id+'_titlerow" >';
    	html[idx++]='<td height="26px" style="width:100px;font-size: 12px;text-align:center" class="nk_menu_td_1 fxeidsetmenu">'+this.lanage.Lanage_fxied+'</td>';
    	html[idx++]='<td height="26px" style="width:100px;font-size: 12px;text-align:center" class="nk_menu_td_1">'+this.lanage.Lanage_show+'</td>';
    	html[idx++]='<td height="26px" style="font-size: 12px;width:{dwidth}px"  class="nk_menu_td_2">'+this.lanage.Lanage_title+'</td>';
    	html[idx++]='</tr>';
        for(var i=0;i<syscells.length;i++){
        	var isSelect=(syscells[i].show==1 || syscells[i].show==3)?"display:'';":"display:none;";//1,3可选择
        	var isShow=(syscells[i].show==1 || syscells[i].show==2)?'checked="checked"':'';//1,2显示
        	var isTRShow=(syscells[i].show==1 || syscells[i].show==2)?'color:'+textColor+';background-color:'+backgroundColor:'';//1,2显示
        	html[idx++]='<tr style="display:block;cursor:default;'+isSelect+''+isTRShow+'" id="nk_'+this.id+'_setrow_'+i+'" >';
        	//----------------列固定-------------------------------------------------------------------------------------------------------
        	html[idx++]='<td height="26px" style="width:100px;" id="nk_'+this.id+'_fxeidcell_'+i+'_0" class="nk_menu_td_1">';
        	html[idx++]='<input type="checkbox" '+isShow+' id="nk_'+this.id+'_fxeidrow_'+i+'_setbox"  value="'+i+'" />';
        	html[idx++]='</td>';
        	//----------------列显示/隐藏---------------------------------------------------------------------------------------------------
        	html[idx++]='<td height="26px" style="width:100px;" id="nk_'+this.id+'_setcell_'+i+'_0" class="nk_menu_td_1">';
        	html[idx++]='<input type="checkbox" '+isShow+' id="nk_'+this.id+'_setrow_'+i+'_setbox"  value="'+i+'" />';
        	html[idx++]='</td><td width="100%" id="nk_'+this.id+'_setcell_'+i+'_1" class="nk_menu_td_2">'+syscells[i].title+'</td>';
        	html[idx++]='</tr>';
        	if(syscells[i].show==1 || syscells[i].show==3)
        		height+=26;
        }
        for(var i=0;i<cells.length;i++){
        	var isSelect=(cells[i].show==1 || cells[i].show==3)?"display:'';":"display:none;";//1,3可选择
        	var isShow=(cells[i].show==1 || cells[i].show==2)?'checked="checked"':'';//1,2显示
        	var isFxied=(cells[i].fixed?'checked="checked"':'');
        	var isTRShow=(cells[i].show==1 || cells[i].show==2)?'color:'+textColor+';background-color:'+backgroundColor:'';//1,2显示
        	html[idx++]='<tr style="cursor:default;'+isSelect+''+isTRShow+'" id="nk_'+this.id+'_setrow_'+(i+syscells.length)+'" >';
        	//--------------列固定------------------------------------------------------------------------------------------------------------------
        	html[idx++]='<td height="26px" style="width:100px;text-align:center" id="nk_'+this.id+'_fxeidcell_'+(i+syscells.length)+'_0" class="nk_menu_td_1 fxeidsetmenu">';
        	html[idx++]='<input type="checkbox" '+isFxied+' id="nk_'+this.id+'_fxeidrow_'+(i+syscells.length)+'_setbox"  value="'+(i+syscells.length)+'" />';
        	html[idx++]='</td>';
        	//--------------列显示/隐藏--------------------------------------------------------------------------------------------------------------
        	html[idx++]='<td height="26px" style="width:100px;text-align:center" id="nk_'+this.id+'_setcell_'+(i+syscells.length)+'_0" class="nk_menu_td_1">';
        	html[idx++]='<input type="checkbox" '+isShow+' id="nk_'+this.id+'_setrow_'+(i+syscells.length)+'_setbox"  value="'+(i+syscells.length)+'" />';
        	html[idx++]='</td><td style="font-size: 12px;width:{dwidth}px"  id="nk_'+this.id+'_setcell_'+(i+syscells.length)+'_1" class="nk_menu_td_2">'+cells[i].title+'</td>';
        	html[idx++]='</tr>';
        	var tempcwidth=$('nk_'+this.id+'_head_a_'+(i+syscells.length)).getWidth();
        	if(cwidth<tempcwidth)
        		cwidth=tempcwidth;
        	if(cells[i].show==1 || cells[i].show==3)
        		height+=26;
        }
        html[idx++]='</table>';
        html[idx++]='</div>';
        cwidth+=200;
        height+=1;
        var div_height = $('div_'+this.id).getHeight();
        if(height>(div_height)){
        	height=(div_height);
        	return html.join('').replace(/\{width\}/g, (cwidth+18)).replace(/\{twidth\}/g, (cwidth)).replace(/\{height\}/g, height);
        }
        return html.join('').replace(/\{width\}/g, (cwidth)).replace(/\{twidth\}/g, (cwidth)).replace(/\{height\}/g, height).replace(/\{dwidth\}/g,(cwidth-24));
    },
    //======================导出EXCEL==================================
    OutExcelUtil : function(prane,typ){
    	var idx = 0;
        var html = [];
        var self=this;
        var cells=this.columnModel;
        if(''!=self.options.outexcelnopage || ''!=self.options.outexcelall || ''!=self.options.outcsvnopage || ''!=self.options.outcsvall || ''!=self.options.outpdfnopage || ''!=self.options.outpdfall){
	        html[idx++]='<div style="display:none;width:0px; height:0px;">';
	        if('pdf'==typ)
	        	html[idx++]='<form action="'+self.exporturl+'" method="post" target="_blank" id="nk_'+self.id+'_nokatag_excel_sqlform" name="nk_'+self.id+'_nokatag_excel_sqlform">';
	        else
	        	html[idx++]='<form action="'+self.exporturl+'" method="post" target="nk_'+self.id+'_nokatag_excel_sqliframe" id="nk_'+self.id+'_nokatag_excel_sqlform" name="nk_'+self.id+'_nokatag_excel_sqlform">';
	        html[idx++]='<input type="submit" id="nk_'+self.id+'_nokatag_excel_sqlform_but" style="display: none;">';
	        html[idx++]='<input type="text"	name="spage"  value="'+self.showpage+'"/>';
	        html[idx++]='<input type="text"	name="typ"  value="'+typ+'"/>';
	        if(''!=self.options.outtitle)
	        	html[idx++]='<input type="text" id=\"'+self.id+'_nokatag_excel_title\"	name="nokatag_excel_title"  value="'+self.options.outtitle+'"/>';
	        if(''!=self.options.outuserfile)
	        	html[idx++]='<input type="text"	name="oufile"  value="'+self.options.outuserfile+'"/>';
	        if('page'==prane)
	        	html[idx++]='<input type="text"	name="pagesize"  value="'+self.options.pagesize+'"/>';
	        if(undefined !=self.countsql)
	        	html[idx++]='<input type="text"	name="countsql"  value="'+self.countsql+'"/>';
	        if(self.options.outfilename!=undefined){
	        	html[idx++]='<input type="text"	name="fname"  value="'+self.options.outfilename+'"/>';
	        }
	        if(self.options.outcustom!=undefined){
	        	html[idx++]='<input type="text" id="'+self.id+'_nokatag_sun_title" name="nokatag_sun_title"  value="'+self.options.outcustom+'"/>';
	        }
	        html[idx++]='<input type="text"	name="pagedescorname"  value="'+self.options.pagedescorname+'"/>';
	        html[idx++]='<input type="text"	name="pagedescorasc"  value="'+self.options.pagedescorasc+'"/>';
	        if(undefined!=self.treesql && 'page'!=prane){
	        	 html[idx++]='<input type="text"	name="sql"  value="'+self.treesql+'"/>';
	        }else{
	        	html[idx++]='<input type="text"	name="sql"  value="'+self.sql+'"/>';
	        }
	        html[idx++]='<input type="text"	name="formatcell"  value="'+self.options.formatcell+'"/>';
	        if(undefined!=self.cellname){
	    		html[idx++]='<textarea name="cells"/>'+Object.toJSON(self.cellname)+'</textarea>';
	    	}
	        html[idx++]='<input type="text"	name="sumformatcell"  value="'+self.options.sumformatcell+'"/>';
	        html[idx++]='<input type="text"	name="sumcellidexs"  value="'+self.sumcellidexs+'"/>';
	        html[idx++]='<input type="text"	name="spage"  value="'+self.showpage+'"/>';
	        html[idx++]='<input type="text"	name="nokatag_excel_allorpage" id="nk_'+self.id+'_excel_all_page"  value="'+prane+'"/>';
	    	if(''!=self.options.nkselect){
	    		try{
		    		$$('#'+self.options.nkselect+' input,select').each(function(alink,index) {
		    			html[idx++]='<input type="text" name="'+alink.name+'"  value="'+alink.value+'"/>';
		    		});
		    		html[idx++]='<input type="text" name="sqlwhere"  value="'+self.options.selectfiled+'"/>';
	    		}catch(e){}
	    	}
	    	var showFide='';
	    	for(var i=0;i<cells.length;i++){
	    		if(cells[i].show==1 || cells[i].show==2)
	    			showFide+=','+i+',';
	    	}
	    	html[idx++]='<input type="text"	name="showfide"  value="'+showFide+'"/>';
	    	html[idx++]='</form>';
	        html[idx++]='<iframe id="nk_'+self.id+'_excel_sqliframe" name="nk_'+self.id+'_nokatag_excel_sqliframe" src="'+self.url+'/dbtable/html/filedownload.htm"></iframe>';
	        html[idx++]='</div>';
	        $('nk_'+self.id+'_outexcel_form_div').innerHTML=html.join('');
	        $('nk_'+self.id+'_nokatag_excel_sqlform_but').click();
        }
    },
    //======================窗体大小改变================================
    resize : function(){
    	var self = this;
    	try{
    		if(self.autosize){//自适应大小
    			self.setWidthAndHeight(0,0);
    		}else{
    			setTimeout(function(){
    	    		self.initFexed();//初始化固定列
    	    		self.initFxiedData();
    	    	},10);
    		}
    		if(undefined!=self.onresize){
    			self.onresize($(self.id));
    		}
    	}catch(e){}
    	try{self.insertInitBlankRow();}catch(e){}//初始化插入行
    },
    //======================设置菜单控制================================
    setMenu : function(){
    	var self = this;
    	var miFlg = true;
    	var textColor= (''==self.options.textColor?'#FFFFFF':self.options.textColor);
    	var backgroundColor=(''==self.options.backgroundColor?'#09C':self.options.backgroundColor);
    	var nsetMenu=$('nk_'+self.id+'_setmenu_div');
    	nsetMenu.observe('mousemove',function(){
    		miFlg = true;
    	});
    	nsetMenu.observe('mouseout',function(event){
    		miFlg = false;
    		var element = event.element();
            setTimeout(function() {
                if (element.descendantOf(nsetMenu) && !miFlg)
                nsetMenu.hide();
            }, 500);
    	});
    	$('nk_'+self.id+'_setimage').observe('mouseout',function(event){
    		miFlg = false;
    		var element = event.element();
            setTimeout(function() {
                if (!miFlg)
                	nsetMenu.hide();
            }, 500);
    	});
    	$('nk_'+self.id+'_setimage').observe('click',function(){
    		var set_menu=$('nk_'+self.id+'_setmenu_div');
         	if(set_menu.getStyle('display')=='none'){
         		miFlg = true;
         		set_menu.absolutize();
         		set_menu.show();
         		var mgboj = $('nk_'+self.id+'_setimage');
         		var set_tab=$('nk_'+self.id+'_setmenu_table');
         		var vwidth = set_tab.getWidth();
         		var dheight = $('div_'+self.id).getHeight()-$('nk_'+self.id+'_bottom_div').getHeight();
         		if(dheight<set_tab.getHeight()){//有滚动条
         			vwidth+=18;
         			set_menu.setStyle({overflow:'auto'});
         		}else{
         			dheight=set_tab.getHeight();
         		}
         		set_menu.setStyle({height:dheight+'px'});
         		var vtop = mgboj.positionedOffset().top-set_menu.getHeight();
         		var vleft = mgboj.positionedOffset().left-set_menu.getWidth()+mgboj.getWidth();
         		set_menu.style.top=vtop;
         		set_menu.style.left=vleft;
         		set_menu.setStyle({left:vleft+'px',top:vtop+'px',width:vwidth+'px',height:dheight+'px'});
         	}else{
         		set_menu.hide();
         	}
    	});
    	$$('tr[id^="nk_'+self.id+'_setrow_"]').each(function(rows,index) {
    		Event.observe(rows,'mousemove', function(){
    			var ln=rows.cells.length;
    		     for(var i=0;i<ln;i++){
    		    	 $(rows.cells[i].id).setStyle({color:textColor,backgroundColor:backgroundColor});
    		     }
    		});
    		Event.observe(rows,'mouseout', function(){
    			 var ln=rows.cells.length;
    			 for(var i=0;i<ln;i++){
    			   $(rows.cells[i].id).setStyle({color:'#000000',backgroundColor:'#FFFFFF'});
    			 }
    		});
//    		Event.observe(rows,'click', function(){
//	   			 $(rows.id+'_setbox').checked=!$(rows.id+'_setbox').checked;
//	   			 self.CellShowOrHide(index,!$(rows.id+'_setbox').checked);
//    		});
        });
    	//---------------------固定列----------------------------------------------
    	$$('input[id^="nk_'+self.id+'_fxeidrow_"]').each(function(checkbox,index) {
    		Event.observe(checkbox,'click', function(event){
    			var e=(event)?event:window.event;
    			var idx = parseInt(checkbox.value.trim());
    			if (window.event) {
    			   e.cancelBubble=true;
    			} else {
    			   e.stopPropagation();
    			}
    			
    			if(checkbox.checked){//选中
	    			for(var i=0;i<=idx;i++){
	    				var FxeidCheckBox = $('nk_'+self.id+'_fxeidrow_'+i+'_setbox');
	    				FxeidCheckBox.checked = true;
	    			}
    			}else{
    				var clen = self.syscells.length+self.columnModel.length;
    				var stid = idx;
    				for(var i=stid;i<clen;i++){
	    				var FxeidCheckBox = $('nk_'+self.id+'_fxeidrow_'+i+'_setbox');
	    				FxeidCheckBox.checked = false;
	    			}
    				idx--;
    			}
    			self.setFxiedCell(idx);
    			self.saveCellMode();
    		});
    	});
    	//---------------------显示/隐藏列操作----------------------------------------
    	$$('input[id^="nk_'+self.id+'_setrow_"]').each(function(checkbox,index) {
    		Event.observe(checkbox,'click', function(event){
    			var e=(event)?event:window.event;
    			if (window.event) {
    			   e.cancelBubble=true;
    			} else {
    			   e.stopPropagation();
    			}
    			self.CellShowOrHide(index,!checkbox.checked);
    		});
    	});
    	$('nk_'+self.id+'_flodingButton').observe('click',function(aimg){
    		if(self.foldingLine){
    			self.foldingLine=false;//不折行显示
    			setTimeout(function(){
        			$$('div[id^=nk_'+self.id+'_dcell_]').each(function(aline){
                        $(aline).addClassName('data_foldingline');
                    });
        			$$('div[id^=nk_'+self.id+'_left_dcell_]').each(function(aline){
                        $(aline).addClassName('data_foldingline');
                    });
        			self.saveFoldingLine(false);
        			self.FxiedFoldingLine();
        		},10);
    			$(this).src=self.url+'/tablegrid/images/zhexingactive.png';
    		}else{
    			self.foldingLine=true;//折行显示
    			setTimeout(function(){
        			$$('div[id^=nk_'+self.id+'_dcell_]').each(function(aline){
                        $(aline).removeClassName('data_foldingline');
                    });
        			$$('div[id^=nk_'+self.id+'_left_dcell_]').each(function(aline){
                        $(aline).removeClassName('data_foldingline');
                    });
        			self.saveFoldingLine(true);
        			self.FxiedFoldingLine();
        		},10);
    			$(this).src=self.url+'/tablegrid/images/zhexingnegative.png';
    		}
    	});
    	$('nk_'+self.id+'_clearsetButton').observe('click',function(aimg){
    		self.ClearCellMode();
    	});
    },
    //==================显示/隐藏列===================================
    CellShowOrHide : function(index,visibleFlg){
    	var cellTd=$('nk_'+this.id+'_head_'+index);
    	var LcellTd=$('nk_'+this.id+'_left_head_'+index);
    	var syscells=this.syscells;
    	var width=parseInt(cellTd.getWidth());//获得该列宽
    	var headTable=$('nk_'+this.id+'_head_table');//表头对像
    	var headWidth=parseInt(headTable.getWidth());
    	try{$('nk_'+this.id+'_head_div').scrollLeft=$('nk_'+this.id+'_data_div').scrollLeft=0;}catch(e){}
    	if(visibleFlg){//hide
    		cellTd.hide();
    		LcellTd.hide();
    		$$('td[id^=nk_'+this.id+'_dcell_'+index+'_]').each(function(element){
                element.hide();
            });
    		$$('td[id^=nk_'+this.id+'_left_dcell_'+index+'_]').each(function(element){
                element.hide();
            });
    		try{this.syscells[index].show=3;}catch(e){}
    		try{this.columnModel[index-syscells.length].show=3;}catch(e){}
    		headWidth-=width;
    		//---------隐藏汇总列----------------------------------
    		try{$('nk_'+this.id+'_sumcells_'+index).hide();}catch(e){}
    		try{$('nk_'+this.id+'_fxied_sumcells_'+index).hide();}catch(e){}
    	}else{//show
    		cellTd.show();
    		LcellTd.show();
    		$$('td[id^=nk_'+this.id+'_dcell_'+index+'_]').each(function(element){
                element.show();
            });
    		$$('td[id^=nk_'+this.id+'_left_dcell_'+index+'_]').each(function(element){
                element.show();
            });
    		try{this.syscells[index].show=1;}catch(e){}
    		try{this.columnModel[index-syscells.length].show=1;}catch(e){}
    		headWidth+=width;
    		//---------隐藏汇总列----------------------------------
    		try{$('nk_'+this.id+'_sumcells_'+index).show();}catch(e){}
    		try{$('nk_'+this.id+'_fxied_sumcells_'+index).show();}catch(e){}
    	}
    	$('nk_'+this.id+'_head_table').setStyle({width: headWidth+ 'px'});
    	$('nk_'+this.id+'_head_table').width=headWidth+'px';
    	$('nk_'+this.id+'_left_head_table').setStyle({width: headWidth+ 'px'});
    	$('nk_'+this.id+'_left_head_table').width=headWidth+'px';
    	var headTable=$('nk_'+this.id+'_head_table');//表头对像
    	var dataWidth=parseInt(headTable.getWidth())-parseInt(this.scrollBarWidth);
		$('nk_'+this.id+'_data_table').setStyle({width: dataWidth+ 'px',tableLayout:'fixed'});
		$('nk_'+this.id+'_left_data_table').setStyle({width: dataWidth+ 'px',tableLayout:'fixed'});
		this.resetoverflowx();
		try{
			$('nk_'+this.id+'_sumcells_table').setStyle({width: dataWidth+ 'px'});
			$('nk_'+this.id+'_sumcells_table').width=dataWidth+'px';
		}catch(e){}
		try{
			$('nk_'+this.id+'_fxied_sumcells_table').setStyle({width: dataWidth+ 'px'});
			$('nk_'+this.id+'_fxied_sumcells_table').width=dataWidth+'px';
		}catch(e){}
		//----------保存设置-----------------------------------------------------
		this.saveCellMode();
		this.initFexed();
		this.initFxiedData();
    },
    //=============================================================
    DataRowClick : function(row){
    	var self = this;
    	var syscells = self.syscells;
    	var row_index = self.getRowIndex(row);//行号
    	for(var a=0;a<syscells.length;a++){
    		try{
    	    	if(4==syscells[a].type || 3==syscells[a].type){//单选或多选
    	    		var checkbox =$('nk_'+self.id+'_dcell_'+a+'_'+row_index+'_checkbox');
    	    		var leftcheckbox =$('nk_'+self.id+'_left_dcell_'+a+'_'+row_index+'_checkbox');
    	    		checkbox.checked=!checkbox.checked;
    	    		leftcheckbox.checked=checkbox.checked;
					self.SelectRowInputValue(checkbox);
					a+=10;
					break;
    	    	}
    		}catch(e){}
    	}
		try{
			self.options.onrowclick(self.RowCreateFunction(row));
		}catch(e){}
    },
    //==================清除帮定方法===================================
    DataaRowClearSelect : function(){
    	var self=this;
    	$$('input[id^="nk_'+self.id+'_check_all"]').each(function(allcheckbox,allindex) {
    		allcheckbox.stopObserving('click');
    	});
    	$$('input[id^="nk_'+self.id+'_left_check_all"]').each(function(allcheckbox,allindex) {
    		allcheckbox.stopObserving('click');
    	});
    	$$('input[id^="nk_'+self.id+'_dcell_"]').each(function(checkbox,index) {
    		checkbox.stopObserving('click');
    	});
    	$$('tr[id^="nk_'+self.id+'_dcell_"]').each(function(row,index) {
    		row.stopObserving('click');
    		row.stopObserving('mousemove');
    		row.stopObserving('mouseout');
    		row.stopObserving('dblclick');
    	});
    	$$('tr[id^="nk_'+self.id+'_dcell_"]').each(function(row,index) {
    		row.stopObserving('click');
    		row.stopObserving('mousemove');
    		row.stopObserving('mouseout');
    		row.stopObserving('dblclick');
    	});
    	$$('tr[id^="nk_'+self.id+'_left_dcell_"]').each(function(row,index) {
    		row.stopObserving('click');
    		row.stopObserving('mousemove');
    		row.stopObserving('mouseout');
    		row.stopObserving('dblclick');
    	});
    	$$('div[id^="nk_'+self.id+'_dcell_"]').each(function(row,index) {
    		row.stopObserving('click');
    		row.stopObserving('mousemove');
    		row.stopObserving('mouseout');
    		row.stopObserving('dblclick');
    	});
    	$$('div[id^="nk_'+self.id+'_left_dcell_"]').each(function(row,index) {
    		row.stopObserving('click');
    		row.stopObserving('mousemove');
    		row.stopObserving('mouseout');
    		row.stopObserving('dblclick');
    	});
    },
    //==================数据选择======================================
    DataRowSelect : function(){
    	var self=this;
    	var textColor= (''==self.options.textColor?'#FFFFFF':self.options.textColor);
    	var backgroundColor=(''==self.options.backgroundColor?'#3FBFF0':self.options.backgroundColor);
    	self.DataaRowClearSelect();
    	$$('input[id^="nk_'+self.id+'_check_all"]').each(function(allcheckbox,allindex) {
    		allcheckbox.observe('click',function(){
        		$$('input[id^="nk_'+self.id+'_dcell_"]').each(function(checkbox,index) {
        			checkbox.checked=$('nk_'+self.id+'_check_all').checked;
        			self.SelectRowInputValue(checkbox);
        		});
        	});
    	});
    	$$('input[id^="nk_'+self.id+'_left_check_all"]').each(function(allcheckbox,allindex) {
    		allcheckbox.observe('click',function(){
    			$('nk_'+self.id+'_check_all').checked = $('nk_'+self.id+'_left_check_all').checked;
        		$$('input[id^="nk_'+self.id+'_dcell_"]').each(function(checkbox,index) {
        			checkbox.checked=$('nk_'+self.id+'_check_all').checked;
        			self.SelectRowInputValue(checkbox);
        		});
        		$$('input[id^="nk_'+self.id+'_left_dcell_"]').each(function(checkbox,index) {
        			checkbox.checked=$('nk_'+self.id+'_check_all').checked;
        			self.SelectRowInputValue(checkbox);
        		});
        	});
    	});
    	$$('input[id^="nk_'+self.id+'_dcell_"]').each(function(checkbox,index) {
    		Event.observe(checkbox,'click', function(event){
    			var e=(event)?event:window.event;
    			if (window.event) {
    			   e.cancelBubble=true;
    			} else {
    			   e.stopPropagation();
    			}
    			if(!checkbox.checked){
    				$('nk_'+self.id+'_check_all').checked=checkbox.checked;
    			}
    			self.SelectRowInputValue(checkbox);
    		});
    	});
    	//-----------------------xiefangjian-----------------------------------------------
    	$$('tr[id^="nk_'+self.id+'_left_dcell_"]').each(function(row,index) {
    		Event.observe(row,'click', function(event){
    			self.DataRowClick(row);
    		});
    		Event.observe(row,'mousemove', function(){
    			var ln=row.cells.length;
    			var idx = row.id.substring(row.id.lastIndexOf('_')+1,row.id.length);
    		     for(var i=0;i<ln;i++){
    		    	 try{$($('nk_'+self.id+'_dcell_'+idx).cells[i].id).setStyle({color:textColor,backgroundColor:backgroundColor});}catch(e){}
    		    	 try{$($('nk_'+self.id+'_left_dcell_'+idx).cells[i].id).setStyle({color:textColor,backgroundColor:backgroundColor});}catch(e){}
    		     }
    		});
    		Event.observe(row,'mouseout', function(){
    			 var ln=row.cells.length;
    			 var idx = row.id.substring(row.id.lastIndexOf('_')+1,row.id.length);
    			 for(var i=0;i<ln;i++){
    				 try{$($('nk_'+self.id+'_dcell_'+idx).cells[i].id).setStyle({color:'',backgroundColor:''});}catch(e){}
    		    	 try{$($('nk_'+self.id+'_left_dcell_'+idx).cells[i].id).setStyle({color:'',backgroundColor:''});}catch(e){}
    			 }
    		});
    		Event.observe(row,'dblclick', function(event){
    			var idx = row.id.substring(row.id.lastIndexOf('_')+1,row.id.length);
    			var drow = $('nk_'+self.id+'_dcell_'+idx);
    			try{
    				self.options.onrowdblclick(self.RowCreateFunction(drow));
    				for(var i=0;i<self.inputData.length;i++){//[{vaule:1,show:1,veri:false,field:'afff'},{}]
    					try{
	    					var inputField = $(self.inputData[i].field);
	    					var value =self.cellNameToIndex(self.inputData[i].value);//字段名称
	    					var show=self.cellNameToIndex(self.inputData[i].show);
	    					var veri=self.inputData[i].veri;
	    					if(inputField!=undefined && value!=undefined){
	    						var va = $(drow.cells[value].id+'_div').innerHTML.hTrim();
	    						if(veri!=undefined){
	    							try{inputField.setValue(va,veri);}catch(e){
	    								inputField.value=value;
	    							}
	    						}else if(show!=undefined){
	    							show = $(drow.cells[show].id+'_div').innerHTML.hTrim();
	    							try{
	    								inputField.setValue(va,show);
	    							}catch(e){
	    								inputField.value=va;
	    							}
	    						}else{
	    							try{inputField.setValue(va);}catch(e){
	    								inputField.value=va;
	    							}
	    						}
	    					}
    					}catch(e){}
    				} 
    			}catch(e){}
        	});
    	});
    	//-----------------------------------------------------------------------
    	$$('tr[id^="nk_'+self.id+'_dcell_"]').each(function(row,index) {
    		Event.observe(row,'click', function(event){
    			self.DataRowClick(row);
    		});
    		Event.observe(row,'mousemove', function(){
    			var ln=row.cells.length;
    			var idx = row.id.substring(row.id.lastIndexOf('_')+1,row.id.length);
    		     for(var i=0;i<ln;i++){
    		    	 try{$($('nk_'+self.id+'_dcell_'+idx).cells[i].id).setStyle({color:textColor,backgroundColor:backgroundColor});}catch(e){}
    		    	 try{$($('nk_'+self.id+'_left_dcell_'+idx).cells[i].id).setStyle({color:textColor,backgroundColor:backgroundColor});}catch(e){}
    		     }
    		});
    		Event.observe(row,'mouseout', function(){
    			 var ln=row.cells.length;
    			 var idx = row.id.substring(row.id.lastIndexOf('_')+1,row.id.length);
    			 for(var i=0;i<ln;i++){
    				 try{$($('nk_'+self.id+'_dcell_'+idx).cells[i].id).setStyle({color:'',backgroundColor:''});}catch(e){}
    		    	 try{$($('nk_'+self.id+'_left_dcell_'+idx).cells[i].id).setStyle({color:'',backgroundColor:''});}catch(e){}
    			 }
    		});
    		Event.observe(row,'dblclick', function(event){
    			//-------------行双单击事件-------------------------------------------------------------------
    			try{
    				self.options.onrowdblclick(self.RowCreateFunction(row));
    				for(var i=0;i<self.inputData.length;i++){//[{vaule:1,show:1,veri:false,field:'afff'},{}]
    					try{
	    					var inputField = $(self.inputData[i].field);
	    					var value =self.cellNameToIndex(self.inputData[i].value);//字段名称
	    					var show=self.cellNameToIndex(self.inputData[i].show);
	    					var veri=self.inputData[i].veri;
	    					if(inputField!=undefined && value!=undefined){
	    						var va = $(row.cells[value].id+'_div').innerHTML.hTrim();
	    						if(veri!=undefined){
	    							try{inputField.setValue(va,veri);}catch(e){
	    								inputField.value=value;
	    							}
	    						}else if(show!=undefined){
	    							show = $(row.cells[show].id+'_div').innerHTML.hTrim();
	    							try{
	    								inputField.setValue(va,show);
	    							}catch(e){
	    								inputField.value=va;
	    							}
	    						}else{
	    							try{inputField.setValue(va);}catch(e){
	    								inputField.value=va;
	    							}
	    						}
	    					}
    					}catch(e){}
    				} 
    			}catch(e){}
    		});
    		//-------------单元格单击编辑--------------------------------------------------------------------
			try{
				var cels = row.cells;
				for(var i=0;i<cels.length;i++){
					Event.observe(cels[i],'click', function(event){
						var rcIndex = self.getRowAndCellIndex(this);//获取列号，行号
						var cellName = self.cellIndexToName(rcIndex.cellIndex);//根据列号取得列名
						if(self.editCells!=undefined && self.editCells.length>0){
							for(var c=0;c<self.editCells.length;c++){
								if(self.editCells[c].cell==cellName || self.editCells[c].cell==rcIndex.cellIndex){//找到可编辑列
									var cfg = self.editCells[c].cfg;
									self.editNowCellRow.cellIndex = c;
									self.editNowCellRow.rowIndex = self.getRowAndCellIndex(this).rowIndex;
									//-----------------------外部初始化方法------------------------------------
									if(!self.onedituser(this,self.editCells[c].oninitedit)){//单元格对象,事件
										return;
									}
									//--------------------------------------------------------------------
									if('input'==cfg.type)
										self.inputTextCreate(this,cfg);//普通录入框
									else if('minput'==cfg.type)
										self.minputTextCreate(this,cfg);//多项录入框
									else if('ajaxinput'==cfg.type)
										self.ajaxinputTextCreate(this,cfg);//ajax录入框
									else if('treeselect'==cfg.type)
										self.ntreeSelectCreate(this,cfg);//树形下拉框
									else if('treetranselect'==cfg.type)
										self.treeTranSelect(this,cfg);//树形下拉框
									else if('dateselect'==cfg.type)
										self.DateSelectCreate(this,cfg);//时间下拉框
									else if('select'==cfg.type)
										self.selectCreate(this,cfg);//下拉选择框
									else if('selectmulti'==cfg.type)
										self.selectMultiCreate(this,cfg);//下拉选择框
									else if('nswitch'==cfg.type)
										self.nswitch(this,cfg);//开关
									return;
								}
							}
						}
					});
				}
			}catch(e){}
    	});
    	//------------------自定义单元格--------------------------------------------------------------
    	$$('div[id^="nk_'+self.id+'_dcell_"]').each(function(row,index) {
    		Event.observe(row,'click', function(event){
    			var checkBox = $(this.id+'_checkbox');
    			if(checkBox!=undefined && (checkBox.type=='checkbox' || checkBox.type=='radio')){
	    			try{
	    				checkBox.checked=!checkBox.checked;
	        			self.SelectRowInputValue(checkBox);
	    				var vjson = $(this.id+'_json').innerHTML.evalJSON();
	    				var obj={checkboxid:this.id+'_checkbox',checked:checkBox.checked,cell:vjson};
	    				self.options.onrowclick(obj);
	    			}catch(e){}
    			}
    		});
    		Event.observe(row,'dblclick', function(event){
    			var checkBox = $(this.id+'_checkbox');
    			if(checkBox!=undefined && (checkBox.type=='checkbox' || checkBox.type=='radio')){
	    			try{
	    				checkBox.checked=!checkBox.checked;
	        			self.SelectRowInputValue(checkBox);
	    				var vjson = $(this.id+'_json').innerHTML.evalJSON();
	    				var obj={checkboxid:this.id+'_checkbox',checked:checkBox.checked,cell:vjson};
	    				self.options.onrowdblclick(obj);
	    			}catch(e){}
    			}
    		});
    		Event.observe(row,'mousemove', function(){
    		    try{$(row.id).setStyle({color:textColor,backgroundColor:backgroundColor});}catch(e){}
    		});
    		Event.observe(row,'mouseout', function(){
    			$(row.id).setStyle({color:'',backgroundColor:''});
    		});
    	});
    },
    //------------根据列名找到所在序号--------------------
    cellNameToIndex : function(title){
    	var self = this;
    	try{
    		for(var i=0;i<self.columnModel.length;i++){
    			if(self.columnModel[i].name==title || self.columnModel[i].title==title)
    				return (i+self.syscells.length);
    		}
    	}catch(e){}
    	return title;
    },
    //------------编辑时调用外部事件---------------------
    onedituser : function(body,oninitedit,inputvalue,showvalu){
    	var self = this;
    	try{
			if(undefined !=oninitedit){
				var valu = self.cellGetValue(body);//获取当前单元格的值
				var rows = self.RowCreateFunction(self.getRowTd(body));//行对象
				var rowsdata = $(rows.id).getRowData();//行数据
				var cellidx = self.getRowAndCellIndex(body);//行号和列号
				//------------设置单元格编辑参数-------------------------------
				body.setEditCells = function(cfg){
					self.tempcellsPars.set(cellidx.cellIndex+'_'+cellidx.rowIndex,cfg);
				};
				//-------------设置行编辑参数---------------------------------
				rows.setEditCells = function(cellIdx,cfg){//设置单元格编辑参数
					self.tempcellsPars.set(cellIdx+'_'+cellidx.rowIndex,cfg);
				};
				var obj = {value:valu,tdobj:body,row:rows,rowdata:rowsdata,editvalue:inputvalue,showvalue:showvalu};//值,单元格对象,行对象,行数据
				if(valu.toLowerCase().indexOf('<div ')==-1){
					var rboj = oninitedit(obj);
					if(undefined == rboj){
						return true;
					}
					return rboj;
				}
			}
		}catch(e){}
		return true;
    },
    onEndEdituser : function(body,oninitedit,inputvalue,showvalu){
    	var self = this;
    	try{
			if(undefined !=oninitedit){
				var bov = self.cellGetValue(body);//获取当前单元格的值
				var valu = self.getOldValue(body);//获取当前单元格的值
				var rows = self.RowCreateFunction(self.getRowTd(body));//行对象
				var rowsdata = $(rows.id).getRowData();//行数据
				var obj = {value:valu,tdobj:body,row:rows,rowdata:rowsdata,editvalue:inputvalue,showvalue:showvalu};//值,单元格对象,行对象,行数据
				if(bov.toLowerCase().indexOf('<div ')!=-1){
					var rboj = oninitedit(obj);
					if(undefined == rboj){
						return true;
					}
					return rboj;
				}
			}
		}catch(e){}
		return true;
    },
    getOldValue : function(body){
    	var self =this;
    	var cellidx = self.getRowAndCellIndex(body);//行号和列号
    	var tavalue = $('nk_'+self.id+'_tdvalue_'+cellidx.cellIndex+'_'+cellidx.rowIndex);
    	return tavalue.value;
    },
    SelectRowInputValue:function(checkbox){ 
       if(checkbox.type=='radio'){
    	   if(checkbox.checked){
    		   $(this.options.checkrecord).value=checkbox.value;
    		   if(undefined!=this.selectMode){
    			   try{
	    			   var v = this.RowCreateFunction(checkbox.parentNode.parentNode.parentNode);
	    			   $(this.selectMode).setValue($(v.cells[1].id+'_div').innerHTML,$(v.cells[2].id+'_div').innerHTML);//给控
    			   }catch(e){}
    		   }
    	   }else{
    		   $(this.options.checkrecord).value='';
    		   if(undefined!=this.selectMode){
    			   try{
    				   $(this.selectMode).setValue('','');//给控
    			   }catch(e){}
    		   }
    	   }
       }else if (checkbox.checked){  
         var vch=$(this.options.checkrecord).value;  
         var sch=$(this.options.checkrecord+'_sv').value; 
         if(vch.length<1){    
            $(this.options.checkrecord).value=checkbox.value;
            if(undefined!=this.selectMode){
            	try{
	 			   var v = this.RowCreateFunction(checkbox.parentNode.parentNode.parentNode);
	 			   $(this.options.checkrecord+'_sv').value=$(v.cells[2].id+'_div').innerHTML;//记录名称
	 			   $(this.selectMode).setValue($(this.options.checkrecord).value,$(this.options.checkrecord+'_sv').value);//给控
            	}catch(e){}
 		    }
         }else{ 
        	if((','+vch+',').indexOf(','+checkbox.value+',')==-1){
        		$(this.options.checkrecord).value=vch+','+checkbox.value; 
        		 if(undefined!=this.selectMode){
                 	try{
     	 			   var v = this.RowCreateFunction(checkbox.parentNode.parentNode.parentNode);
     	 			   $(this.options.checkrecord+'_sv').value=sch+','+$(v.cells[2].id+'_div').innerHTML;//记录名称
     	 			   $(this.selectMode).setValue($(this.options.checkrecord).value,$(this.options.checkrecord+'_sv').value);//给控
                 	}catch(e){}
      		    }
        	}
         } 
       }else{  
        var vch=$(this.options.checkrecord).value; 
        vch=','+vch+',';
        var vc=','+checkbox.value+',';
        var reg=new RegExp(vc); 
        var nvalue=vch.replace(reg,',');   
        if(nvalue.length<=1){
        	$(this.options.checkrecord).value='';
        	if(undefined!=this.selectMode){
             	try{
 	 			   $(this.selectMode).setValue('','');//给控
             	}catch(e){}
  		    }
        }else{
        	$(this.options.checkrecord).value=nvalue.substring(1,nvalue.length-1).trim(); 
        	try{
        		var sch=$(this.options.checkrecord+'_sv').value; 
        		sch=','+sch+',';
        		var v = this.RowCreateFunction(checkbox.parentNode.parentNode.parentNode);
        		var sc=','+$(v.cells[2].id+'_div').innerHTML+',';
        		var regh=new RegExp(sc); 
                var nvalueh=sch.replace(regh,',');  
                $(this.options.checkrecord+'_sv').value = nvalueh.substring(1,nvalueh.length-1).trim();
                $(this.selectMode).setValue($(this.options.checkrecord).value,$(this.options.checkrecord+'_sv').value);//给控
        	}catch(e){}
        }
       }
       try{
    	   this.options.onrowclick(this.RowCreateFunction(checkbox.parentNode.parentNode.parentNode));
       }catch(e){
       }
      },
    //==================子表操作方法==================================
    SubTableUtil : function(){
    	var self = this;
    	$$('img[id^="nk_'+self.id+'_dcell_subimage_"]').each(function(img,index) {
            $(img).observe('click', function() {
            	var subTr=$('nk_'+self.id+'_subcell_'+index);
            	
            	if(subTr.getStyle('display')=='none'){
            		subTr.show();
            		$(img).src=self.url+'/tablegrid/images/minu_tales.gif';
            		self.SubTableLoad(index,$('nk_'+self.id+'_dcell_'+index),$(subTr.id+'_td'));//加载子表数据
             	}else{
             		subTr.hide();
             		$(img).src=self.url+'/tablegrid/images/plus_table.gif';
             	}
            });
        });
    },
    //===================树形表=======================================
    TreeTableUtil : function(){
    	var self = this;
    	$$('img[id^="nk_'+self.id+'_dcell_treeimage_"]').each(function(img,index) {
            $(img).observe('click', function() {
            	self.TreeTableNodeClick(img);
            });
        });
    },
    TreeTableUtilIndex : function(rowindex){
    	var self = this;
    	var sidx = self.syscells.length-1;
    	var img = $('nk_'+self.id+'_dcell_treeimage_'+sidx+'_'+rowindex);
    	try{
	    	if(undefined!=img){
	    		img.observe('click', function() {
	    			self.TreeTableNodeClick(img);
	    		});
	    	}
    	}catch(e){}
    },
    TreeTableNodeClick : function(img){
    	var self = this;
    	var rowtd = undefined;
    	try{
	    	rowtd=self.getRowAndCellIndex(img);
	    	if(img.hasClassName('nodata')){
	    		return;
	    	}
	    	if(img.hasClassName('opennode')){//打开状态
	    		try{
	        		var rows = self.RowCreateFunction(self.getRowTd(img));//行对象
	    	    	if(!self.treeclick(false,rows)){
	    	    		return;
	    	    	}
	        	}catch(e){}
	    		self.deltreeNode(rowtd.rowIndex);
	    		img.removeClassName('opennode');
	    		$(img).src=self.url+'/tablegrid/images/plus_table.gif';
	    	}else{
	    		try{
	        		var rows = self.RowCreateFunction(self.getRowTd(img));//行对象
	    	    	if(!self.treeclick(true,rows)){
	    	    		return;
	    	    	}
	        	}catch(e){}
	    		self.loadTreeNode(rowtd.rowIndex);
	    		img.addClassName('opennode');
	    		$(img).src=self.url+'/tablegrid/images/minu_tales.gif';
	    	}
    	}catch(e){}
    },
    //=================加载树形节点数据==================================
    loadTreeNode : function(rowindex){//行号
    	var self = this;
    	$('nk_'+self.id+'_load_dataing').show();//显示加载数据
    	var pars = self.getTreePars(rowindex);//获取查询参数
    	var sidx = self.syscells.length-1;
    	var img = $('nk_'+self.id+'_dcell_treeimage_'+sidx+'_'+rowindex);
    	new Ajax.Request(self.dataurl, {
            parameters: pars,
            method:'post',
            onSuccess: function(response) {
            	$('nk_'+self.id+'_load_dataing').hide();
            	try{
	                var tableModel = response.responseText.evalJSON();
	                if(tableModel.rows.length>0){
	                	self.insertDataRows(tableModel.rows,function(){return true;},rowindex);
	                }else{
	                	$(img).src=self.url+'/tablegrid/images/tabpage.png';
	                	img.addClassName('nodata');
	                }
            	}catch(e){}
            },
            //---------------------失败-----------------------------------------
        	onFailure : function(transport) {
        		$('nk_'+this.id+'_load_dataing').hide();
            }
    	});
    },
    //---------------删除历史数据-------------------------------------------------
    deltreeNode : function(rowindex){
    	var self = this;
    	var pclass='';
    	try{pclass = $('nk_'+self.id+'_dcell_'+rowindex).className;}catch(e){}
    	if(undefined!=pclass && pclass.trim().length>0){
    		$$('tr[class^="'+pclass+rowindex+'"]').each(function(row,index) {
        		row.remove();
        	});
    	}
    	$$('tr[class^="pclassid_'+rowindex+'_"]').each(function(row,index) {
    		row.remove();
    	});
    },
    //---------------获取树形菜单查询参数--------------------------------------------
    getTreePars : function(rowindex){
    	var self = this;
    	var pars=[];
    	var ix=0;
    	pars[ix++]='spage=1';
    	pars[ix++]='&sql='+self.treesql;
    	if(''!=self.options.pagedescorname && ''!=self.options.pagedescorasc){
	    	pars[ix++]='&pagedescorname='+self.options.pagedescorname;
	    	pars[ix++]='&pagedescorasc='+self.options.pagedescorasc;
    	}
    	if(self.options.onDataLoad!=undefined){
    		pars[ix++]='&onDataLoad='+self.options.onDataLoad;
    		pars[ix++]='&queryjson='+encodeURIComponent(self.getSelectValues().toJSON());
    	}
    	if(''!=self.options.formatcell){
    		pars[ix++]='&formatcell='+self.options.formatcell;
    	}
    	if(undefined!=self.columnModel){
    		pars[ix++]='&cells='+encodeURIComponent(Object.toJSON(self.columnModel));
    	}
    	if(''!=self.options.sumformatcell){
    		pars[ix++]='&sumformatcell='+self.options.sumformatcell;
    	}
    	if(''!=self.options.dataclass)
    		pars[ix++]='&dataclass='+self.options.dataclass;
    	if('-1'!=self.sumcellidexs){
    		pars[ix++]='&sumcellidexs='+self.sumcellidexs;
    	}
    	pars[ix++]='&'+self.options.ajaxPrave;
    	//-----------------------------------------------------
    	if(undefined!=self.findtreenode){
    		for(var i=0;i<self.findtreenode.length;i++){//[{cell:'MENUID',vcell:'MENUID'}]
    			pars[ix++]="&"+self.findtreenode[i].cell+'='+encodeURIComponent(self.getCellTd(rowindex,self.findtreenode[i].vcell).innerHTML);
    		}
    		pars[ix++]='&sqlwhere='+self.options.treeselectfiled;
    	}
    	return pars.join('');
    },
    //==================动态排序======================================
    DataSequence : function(){
    	var self = this;
    	var cells=self.columnModel;
        var cidx=self.syscells.length;
        $$('a[id^="nk_'+self.id+'_left_head_a_"]').each(function(checkbox,index) {
        	var oidx = 0;
    		var sort = self.sort;
    		try{
    			oidx = checkbox.id.substring(checkbox.id.lastIndexOf('_')+1,checkbox.id.length);
        		sort = (undefined == cells[oidx-cidx].sort?self.sort:cells[index-cidx].sort);
    		}catch(e){}
    		if(sort){
    			 $(checkbox).observe('click', function() {
    				 self.sortDisplay(oidx);
    			 });
    		}
        });
    	$$('a[id^="nk_'+self.id+'_head_a_"]').each(function(checkbox,index) {
    		var oidx = 0;
    		var sort = self.sort;
    		try{
    			oidx = checkbox.id.substring(checkbox.id.lastIndexOf('_')+1,checkbox.id.length);
        		sort = (undefined == cells[oidx-cidx].sort?self.sort:cells[index-cidx].sort);
    		}catch(e){}
    		if(sort){
	            $(checkbox).observe('click', function() {
	               self.sortDisplay(oidx);
	            });
    		}
        });
    },
    //----------------排序操作---------------------------------------------
    sortDisplay : function(oidx){
    	var self = this;
    	var fixeda =  $('nk_'+self.id+'_left_head_a_'+oidx);
    	var heada = $('nk_'+self.id+'_head_a_'+oidx);
		var fsequ=$(fixeda.id+'_sequ');
		var hsequ=$(heada.id+'_sequ');
        var corname = heada.innerHTML;
        try{
            corname = $(heada.id+'_name').value;
        }catch(xe){}
        try{
            var img=$(self.tempdescorascimg);
            var imgFixed=$(self.tempdescorascimgFixed);
            img.src='';
            img.hide();
            imgFixed.src='';
            imgFixed.hide();
        }catch(e){}
            self.tempdescorascimg=hsequ.id;
            self.tempdescorascimgFixed=fsequ.id;
            if(self.options.pagedescorname==corname && self.options.pagedescorasc=="asc"){
            	self.options.pagedescorasc="desc";
            	fsequ.src=self.url+'/tablegrid/images/sort-arrow-desc.png';
            	fsequ.title=self.lanage.Lanage_sequDesc;
            	fsequ.alt=self.lanage.Lanage_sequDesc;
            	
            	hsequ.src=self.url+'/tablegrid/images/sort-arrow-desc.png';
            	hsequ.title=self.lanage.Lanage_sequDesc;
            	hsequ.alt=self.lanage.Lanage_sequDesc;
            }else{
            	self.options.pagedescorasc="asc";
            	fsequ.src=self.url+'/tablegrid/images/sort-arrow-asc.png';
            	fsequ.title=self.lanage.Lanage_sequAsc;
            	fsequ.alt=self.lanage.Lanage_sequAsc;
            	
            	hsequ.src=self.url+'/tablegrid/images/sort-arrow-asc.png';
            	hsequ.title=self.lanage.Lanage_sequAsc;
            	hsequ.alt=self.lanage.Lanage_sequAsc;
            }
            self.options.pagedescorname=corname;
            self.showpage=1;
            self.LoadData();
            hsequ.show();
            fsequ.show();
    },
    getDescOrAscImg :function(){
    	var desc={title:'',url:''};
    	if('desc'==this.options.pagedescorasc){
    		desc.title=this.lanage.Lanage_sequDesc;
    		desc.url=this.url+'/tablegrid/images/sort-arrow-desc.png';
    	}else{
    		desc.title=this.lanage.Lanage_sequAsc;
    		desc.url=this.url+'/tablegrid/images/sort-arrow-asc.png';
    	}
    	return desc;
    },
    //==================提交form=====================================
    AjaxSubmitDataFormPars : function(xpar){
    	var idx=0;
    	var pars=[];
    	var self=this;
    	var formactionurl=$(self.options.tableformid).action;//数据表的提交地址
    	var data = xpar.data;//提交的附加数据
    	var formid=xpar.formid;//提交外部表单的值
    	var ajaxurl = (undefined==xpar.url?formactionurl:xpar.url);//提交到指定的url
    	var asynchronou=xpar.asynchronou;//是否异步提交
    	var sformNull = (undefined==xpar.formNull?self.formNull:xpar.formNull);//为空时的提示信息
    	var sformConfirmation=(undefined==xpar.formConfirmation?self.formConfirmation:xpar.formConfirmation);//提交前的确认信息
    	
    	if(!self.options.onsubmit($(self.options.tableformid)))
    		return;
    	//-----------内部表单数据-------------------------------------
    	$$('#'+self.options.tableformid+' input,select,textarea').each(function(alink,index) {
    		if(alink.type=='checkbox' || alink.type=='radio'){
    			if(alink.checked){
    				if(''!=alink.name){
    					pars[idx++]='&'+alink.name+'='+encodeURIComponent(alink.value);
    				}
    			}
    		}else{
    			if(''!=alink.name){
    				pars[idx++]='&'+alink.name+'='+encodeURIComponent(alink.value);
    			}
    		}
		});
    	//----------附加数据-----------------------------------------
    	try{
    		if(undefined !=data && data instanceof Array){
    			for(var i=0;i<data.length;i++){
    				pars[idx++]='&'+data[i].name+'='+data[i].value;
    			}
    		}
    	}catch(e){}
    	//----------外部表单数据-------------------------------------
    	try{
    		if(undefined !=formid){//外部表单
    			var formpars = self.GetFormPars(formids);
				if(formpars.vri){
					pars[idx++]=formpars.data;
				}
    		}
    	}catch(e){}
    	//---------提交表单数据----------------------------------------
    	if(sformNull!='' && $(self.options.checkrecord).value==''){//不能为空，参数为空，不能提交form
    		alert(sformNull);
    	}else{
    		var cr = true;
    		if(sformConfirmation!=''){//显示确认信息
    			cr = confirm(sformConfirmation);
    		}
    		if(cr==true){
		    	new Ajax.Request(ajaxurl, {
		            parameters: pars.join(''),
		            method:'post',
		            asynchronous:(undefined==asynchronou?true:asynchronou),//是否异步提交
		            onSuccess: function(response) {
		            	try{
		            		self.options.onsuccess(response);
		            	}catch(e){}
		            },
		            onFailure : function(response) {
		            	self.options.onfailure(response);
		            }
		    	});
    		}
    	}
    },
    //==================提交form=====================================
    AjaxSubmitDataForm : function(data,asynchronou){//[{name:'a',value:'a'},{name:'b',value:'1'}]
    	var pars = {};
    	var self = this;
    	if(undefined==asynchronou){
    		pars.asynchronou = true;//默认为异步提交
    	}
    	if(undefined !=data){
    		if( data instanceof Array ){
    			pars.data = data;
    		}else{
    			pars.formid=data;
    		}
    	}
    	self.AjaxSubmitDataFormPars(pars);
    },
    //------------检查form是否有选项---------------------------------------
    getFormSelect : function(){
    	if($(this.options.checkrecord).value==''){
    		return [];
    	}
    	return  $(this.options.checkrecord).value.split(",");
    },
    setDBGridValue : function(vaues){
    	var self=this;
    	if(!self.options.onsubmit($(self.options.tableformid)))
    		return;
    	$$('#'+self.options.tableformid+' input').each(function(alink,index) {
    		for(var i=0;i<vaues.length;i++){
	    		if((alink.type=='checkbox' || alink.type=='radio') && vaues[i]==alink.value){
	    			alink.checked=true;
	    		}
    		}
		});
    	$(self.options.checkrecord).value = vaues.join(",");
    },
    //==================附加方法======================================
    ObjectAddEvent : function(){
    	var self = this;
    	var scrotop = $('nk_'+self.id+'_data_div').scrollTop;
    	//-----------滚动条事件----------------------------
    	$('nk_'+self.id+'_data_div').observe('scroll',function(){
    	   //-----------------横向滚动-------------------------------------------------------------------
    	   $('nk_'+self.id+'_head_div').scrollLeft=$('nk_'+self.id+'_data_div').scrollLeft;
    	   try{
    		   $('nk_'+self.id+'_sumcelldiv').scrollLeft=$('nk_'+self.id+'_data_div').scrollLeft;
    	   }catch(e){}
    	   try{
    		   $('nk_'+self.id+'_sumcells_div').scrollLeft=$('nk_'+self.id+'_data_div').scrollLeft;
    	   }catch(e){}
    	   try{
    		   $('nk_'+self.id+'_left_data_div').scrollTop=$('nk_'+self.id+'_data_div').scrollTop;
    	   }catch(e){}
    	   //-----------------纵向滚动------------------------------------------------------------------
    	   var ptop = $('nk_'+self.id+'_data_div').scrollTop+10;
    	   var scrollHeight = $('nk_'+self.id+'_data_div').scrollHeight;
    	   var pheight = $('nk_'+self.id+'_data_div').getHeight();
    	   if(scrotop<=ptop && (scrollHeight-pheight)<=ptop){//开始插入数据
    		   self.insertDataRowsAdd();
    	   }
    	});
    	//------------窗体大小改变--------------------------
    	Event.observe(window, 'resize', function(){
    		self.resize();
    	});
    	//------------设置菜单控制-------------------------
    	this.setMenu();
    	//------------排序--------------------------------
    	this.DataSequence();
    	//-------------查询-------------------------------
    	if(''!=self.options.selectfiled && 'nk_'+self.id+'_select_div'==self.options.nkselect){
    		$('nk_'+self.id+'_select_button').observe('click',function(){
    			self.showpage=1;
    			self.LoadData();
    	    });
    	}
    	//------------excel------------------------------
    	if(''!=self.options.outexcelnopage){
	        $('nk_'+self.id+'_outexcel_page').observe('click',function(event){
	    		self.OutExcelUtil('page','excel');
	    	});
        }
        if(''!=self.options.outexcelall){
	        $('nk_'+self.id+'_outexcel_alldata').observe('click',function(event){
	        	self.OutExcelUtil('all','excel');
	    	});
        }
      //------------csv------------------------------
    	if(''!=self.options.outcsvnopage){
	        $('nk_'+self.id+'_outcsv_page').observe('click',function(event){
	    		self.OutExcelUtil('page','csv');
	    	});
        }
        if(''!=self.options.outcsvall){
	        $('nk_'+self.id+'_outcsv_alldata').observe('click',function(event){
	        	self.OutExcelUtil('all','csv');
	    	});
        }
        //------------pdf------------------------------
    	if(''!=self.options.outpdfnopage){
	        $('nk_'+self.id+'_outpdf_page').observe('click',function(event){
	    		self.OutExcelUtil('page','pdf');
	    	});
        }
        if(''!=self.options.outpdfall){
	        $('nk_'+self.id+'_outpdf_alldata').observe('click',function(event){
	        	self.OutExcelUtil('all','pdf');
	    	});
        }
        $('nk_'+this.id+'_reLoadData').observe('click',function(event){
        	self.reLoadData();
    	});
        //------------reload img-------------------------
        if(''!=this.options.reload){
	        $('nk_'+this.id+'_reload_img').observe('click',function(event){
	        	self.reLoadData();
	    	});
        }
        //------------ajaxsubmitform---------------------
        $('nk_'+this.id+'_AjaxSubmitDataForm').observe('click',function(event){
        	self.AjaxSubmitDataForm();
        });
        //-----------------------------------------------
        if(this.options.editRow!=undefined){
            if(this.options.editRow.addEdit)
            	$('nk_'+this.id+'_button_insert_row').observe('click',function(event){
         	        self.insertDataRow();//添加行
         	    });
            if(this.options.editRow.delEdit)
            	$('nk_'+this.id+'_button_del_row').observe('click',function(event){
         	       	self.deleteDataRow();//删除行
         	    });
        }
        //-----------------------------------------------
        if(this.editAllSubmitAction){
        	$('nk_'+this.id+'_button_eidt_submit_all').observe('click',function(event){
 	        	self.editAjaxSubmitAll();//提交所有数据
 	        });
        }
        //-----------------------------------------------
        $(self.id).reinit = function(){self.rshow(self.target);};
        $(self.id).reload = function(a){self.reLoadData(a);};
        $(self.id).ajaxSubmitDataForm=function(d,c){self.AjaxSubmitDataForm(d,c);};
        $(self.id).ajaxSubmitDataFormPars=function(pars){self.AjaxSubmitDataFormPars(pars);};
        $(self.id).getFormSelect = function(){return self.getFormSelect();};
        $(self.id).setFormSubmitInfo = function(a,b){self.setFormSubmitInfo(a,b);};
        $(self.id).setValue = function(a){self.setDBGridValue(a);};
        $(self.id).getData = function(){return self.getGridData();};
        $(self.id).insertDataRow = function(a,b){return self.insertDataRow(a,b);};
        $(self.id).insertDataRows = function(a,b,c){return self.insertDataRows(a,b,c);};
        $(self.id).delSelectRow = function(){self.deleteDataRow();};
        $(self.id).ajaxSubmitAllEdit = function(a,c){self.editAjaxSubmitAll(a,c);};
        $(self.id).ReCreateDbgrid = function(a,b){self.ReCreateDbgrid(a,b);};//重新生成dbgrid
        $(self.id).setEditCell=function(a){self.setEditCell(a);};//设置可编辑列
        $(self.id).setCellVisible=function(a,b){self.setCellVisible(a,b);};
        $(self.id).setCustom=function(a){self.SetCustom(a);};//设置custom栏内容
        $(self.id).setTitle=function(a){self.setTitle(a);};//设置标题
        $(self.id).setPageSize=function(a){self.options.pagesize=a;};//设置页大小
        $(self.id).setOutTile=function(a){self.options.outtitle=a;};//设置导出标题
        $(self.id).setOutCustom=function(a){self.options.outcustom=a;};//设置导出统计栏
        $(self.id).getSelectRow=function(){return self.getSelectRow();};//获取当前选中行对象
        $(self.id).getSelectRows=function(){return self.getSelectRows();};//获取当前选中行对象
        $(self.id).setSize=function(w,h){self.setGridWidthAndHeight(w,h);};//设置表格大小
        $(self.id).delRowFilter = function(a,b){self.deleteDataRowFilter(a,b);};//按条件删除
        $(self.id).setWidthHeihgt = function(w,h){self.width=w;self.heigth=h;self.autosize=false;};//设高宽
        $(self.id).setAutosize = function(a,b){self.autosize=('true'==a);self.autowidth=('true'==b);};//设置自动计算参数
    },
    setFormSubmitInfo : function(a,b){
    	this.formNull = a;
    	this.formConfirmation = b;
    },
    //============批量插入==================================================
    insertDataRows : function(rowsData,fun,rowindx){
    	var self = this;
    	self.insertDatas = rowsData;//全部数据
    	self.insertFun = fun;
    	self.insertDataRowsAdd(rowindx);
    },
    //============增量插入==================================================
    insertDataRowsAdd : function(rowindx){
    	var self = this;
    	var maxGroup = 5;
    	var sunrowsheigth = self.rowHeight * (self.rowDatas.length<1?1:self.rowDatas.length);//现在表格的总高度
    	var pheight = $('nk_'+self.id+'_data_div').getHeight();//表格固定高度
    	var inrows = Math.ceil((pheight-sunrowsheigth)/self.rowHeight);//还可以插入的行数
    	if(self.insertDatas.length<1){
    		return;
    	}
    	$('nk_'+self.id+'_load_dataing').show();//显示加载数据
    	inrows = (inrows<0?maxGroup:inrows+3);//如果小0，则插入maxGroup行，否则插满表格
    	inrows = (inrows>self.insertDatas.length?self.insertDatas.length:inrows);
    	for(var i=0;i<inrows;i++){
    		if(undefined !=self.insertFun){
    			if(self.insertFun($(self.id),self.insertDatas[i])){
    				self.insertDataRow(self.insertDatas[i],rowindx);
    			}
    		}else{
    			self.insertDataRow(self.insertDatas[i],rowindx);
    		}
    	}
    	self.insertDatas.splice(0,inrows);
    	setTimeout(function(){
    		$('nk_'+self.id+'_load_dataing').hide();//显示加载数据
    	}, (inrows*10));
    },
    //-------------------------------------------------------------------
    reLoadData : function(a){
    	var self = this;
    	if(undefined!=a && a){//回到第一页，默认保留页码
    		self.showpage=1;
    	}
    	if(''!=self.initdescorname && ''!=self.initdescorasc){
            self.options.pagedescorname=self.initdescorname;
        	self.options.pagedescorasc=self.initdescorasc;
    	}
    	try{
            var img=$(self.tempdescorascimg);
            var imgFixed=$(self.tempdescorascimgFixed);
            img.src='';
        	img.hide();
        	imgFixed.src='';
        	imgFixed.hide();
        	
            self.tempdescorascimg=self.initdescorascimg;
            self.tempdescorascimgFixed=self.initdescorascimg;
            var desc=self.getDescOrAscImg();
            var timg=$(self.tempdescorascimg);
            var ftimg=$(self.tempdescorascimgFixed);
            timg.src=desc.url;
            timg.title=desc.title;
            timg.alt=desc.title;
            timg.show();
            
            ftimg.src=desc.url;
            ftimg.title=desc.title;
            ftimg.alt=desc.title;
            ftimg.show();
            
    	 }catch(e){}
    	 $(this.options.checkrecord).value='';//清空翻页记录
    	self.LoadData();
    },
    //-------------重设列宽--------------------------------------------
    ResetCellWidth : function(index,cwidth){
    	try{
	    	if(cwidth<0)
	    		cwidth=-cwidth;
	    	if(cwidth<10)
	    		return;
	    	var cellMinWidth=$('nk_'+this.id+'_head_'+index+'_div_div');
	    	var LcellMinWidth=$('nk_'+this.id+'_left_head_'+index+'_div_div');
	    	var self=this;
	    	var cellTd=$('nk_'+this.id+'_head_'+index);
	    	var LcellTd=$('nk_'+this.id+'_left_head_'+index);
	    	var fcellTd=$('nk_'+this.id+'_fxied_head_'+index);
	    	var owidth=parseInt(cellTd.width);//获得该列表头列宽
	    	var newwidth=parseInt(cwidth);//新的列宽
	    	this.columnModel[index-this.syscells.length].width=newwidth;
	    	var dcwidth=newwidth;
	    	//----------设置表头宽度---------------------------------
	    	var headTable=$('nk_'+this.id+'_head_table');//表头对像
	    	var LheadTable=$('nk_'+this.id+'_left_head_table');//表头对像
	    	if(owidth>newwidth){
	    		cellMinWidth.setStyle({width: (newwidth)+'px'});
		    	cellMinWidth.width=(newwidth)+'px';
		    	LcellMinWidth.setStyle({width: (newwidth)+'px'});
		    	LcellMinWidth.width=(newwidth)+'px';
	    	}
	    	cellTd.setStyle({width: newwidth+'px'});
	    	cellTd.width=newwidth+'px';
	    	LcellTd.setStyle({width: newwidth+'px'});
	    	LcellTd.width=newwidth+'px';
	    	try{
	    		fcellTd.setStyle({width: newwidth+'px'});
	    		fcellTd.width=newwidth+'px';
	    	}catch(e){}
	    	var hwidht = (parseInt(headTable.getWidth())+newwidth)-owidth;
	    	headTable.setStyle({width: hwidht+'px'});
	    	headTable.width=hwidht+'px';
	    	LheadTable.setStyle({width: hwidht+'px'});
	    	LheadTable.width=hwidht+'px';
	    	if(owidth<newwidth){
		    	cellMinWidth.setStyle({width: (cellTd.getWidth()-1)+'px'});
		    	cellMinWidth.width=(cellTd.getWidth()-1)+'px';
		    	LcellMinWidth.setStyle({width: (cellTd.getWidth()-1)+'px'});
		    	LcellMinWidth.width=(cellTd.getWidth()-1)+'px';
		    	dcwidth=cellTd.getWidth()-1;
	    	}
	    	//----------设置表体宽度--------------------------------------------------
			self.resetDataCellWidth(index, dcwidth,owidth);
			//----------设置自定义汇总列宽度---------------------------------------------
			self.resetSumcellsWidth(index, newwidth, owidth);
			//----------保存设置-----------------------------------------------------
			self.saveCellMode();
    	}catch(e){
    	}
    },
    resetDataCellWidth : function(index,newwidth,owidth){
    	try{
	    	var dataTable = $('nk_'+this.id+'_data_table');
	    	var LdataTable = $('nk_'+this.id+'_left_data_table');
	    	var crdit=0;
			$$('div[id^=nk_'+this.id+'_dcell_'+index+'_]').each(function(cell){
					 cell.width=newwidth+ 'px';
					 cell.setStyle({width: newwidth+ 'px'});
			});
			$$('div[id^=nk_'+this.id+'_left_dcell_'+index+'_]').each(function(cell){
				 cell.width=newwidth+ 'px';
				 cell.setStyle({width: newwidth+ 'px'});
			});
			$$('td[id^=nk_'+this.id+'_dcell_'+index+'_]').each(function(cell){
				cell.width=(newwidth-crdit)+ 'px';
				cell.setStyle({width: (newwidth-crdit)+ 'px'});
			});
			$$('td[id^=nk_'+this.id+'_left_dcell_'+index+'_]').each(function(cell){
					cell.width=(newwidth-crdit)+ 'px';
					cell.setStyle({width: (newwidth-crdit)+ 'px'});
			});
			var headTable=$('nk_'+this.id+'_head_table');//表头对像
			dcellwidth=parseInt(headTable.getWidth())-parseInt(this.scrollBarWidth)-crdit;
			dataTable.setStyle({width: dcellwidth+ 'px',tableLayout:'fixed'});
			LdataTable.setStyle({width: dcellwidth+ 'px',tableLayout:'fixed'});
			this.initFexed();
			this.resetoverflowx();
			this.initFxiedData();
    	}catch(e){}
    },
    //----------------重设自动汇总列宽度-------------------------------------
    resetSumcellsWidth : function(index,newwidth,owidth){
    	try{
	    	 var dataTable = $('nk_'+this.id+'_sumcells_table');
	    	 var fdataTable = $('nk_'+this.id+'_fxied_sumcells_table');
	    	 var headTable=$('nk_'+this.id+'_head_table');//表头对像
	    	 var crdit=0;
	    	 var cellDiv = $('nk_'+this.id+'_sumcells_'+index+'_div_div');
	    	 var fcellDiv = $('nk_'+this.id+'_fxied_sumcells_'+index+'_div_div');
	    	 var thDiv = $('nk_'+this.id+'_sumcells_'+index);
	    	 var fthDiv = $('nk_'+this.id+'_fxied_sumcells_'+index);
	    	 
	    	 cellDiv.width=newwidth+ 'px';
	    	 cellDiv.setStyle({width: newwidth+ 'px'});
	    	 
	    	 fcellDiv.width=newwidth+ 'px';
	    	 fcellDiv.setStyle({width: newwidth+ 'px'});
	    	 
	    	 thDiv.width=(newwidth-crdit)+ 'px';
	    	 thDiv.setStyle({width: (newwidth-crdit)+ 'px'});
	    	 fthDiv.width=(newwidth-crdit)+ 'px';
	    	 fthDiv.setStyle({width: (newwidth-crdit)+ 'px'});
	    	 
			 dcellwidth=parseInt(headTable.getWidth())-parseInt(this.scrollBarWidth)-crdit;
			 dataTable.width=dcellwidth+'px';
			 dataTable.setStyle({width: dcellwidth+ 'px'});
			 
			 fdataTable.width=dcellwidth+'px';
			 fdataTable.setStyle({width: dcellwidth+ 'px'});
    	}catch(e){
    	}
    },
    //----------------拖动列宽--------------------------------------------
    DraggableCellWidth : function(){
    	var self=this;
    	var resizeMarkerRight=$('resizeMarkerRight_'+self.id+'_draag');
    	var resizeMarkerLeft=$('resizeMarkerLeft_'+self.id+'_draag');
    	var sCIndex=-1;
    	self.activeDraggable=false;
    	var resizeMarkerLeftTops=false;
    	//------------------------------------------------------------------------------------------
    	$$('div[id^=nk_'+self.id+'_left_head_drag_]').each(function(cell){
    		cell.observe('mousedown',function(event){
    			Event.stop(event);
    			var cellIndex=parseInt(cell.id.substring(cell.id.lastIndexOf('_') + 1, cell.id.length));
        		sCIndex=cellIndex;
        		self.activeDraggable=true;
        		resizeMarkerLeftTops=true;
        		
            	var LineHeight=$('nk_'+self.id+'_head_div').getHeight()+$('nk_'+self.id+'_data_div').getHeight();
        		var cellObj=$('nk_'+self.id+'_head_'+sCIndex);
    			var topPos=0;
    	    	if(''!=self.options.title){
    	    		topPos=$('nk_'+self.id+'_title_div').getHeight();
    	    	}
    			try{
    				var cleft=parseInt(parseInt(cellObj.offsetLeft)+parseInt(cellObj.getWidth()))-parseInt(cellObj.cumulativeScrollOffset()[0])-1;
    				resizeMarkerRight.setStyle({left:cleft+'px',top:topPos+'px',height:LineHeight+'px'});
    				resizeMarkerRight.show();
    			}catch(e){}
    			if(resizeMarkerLeftTops){
    				try{
    					var cleft=parseInt(parseInt(cellObj.offsetLeft)-parseInt(cellObj.cumulativeScrollOffset()[0]));
    					resizeMarkerLeft.setStyle({left:cleft+'px',top:topPos+'px',height:LineHeight+'px'});
    					resizeMarkerLeft.show();
    					resizeMarkerLeftTops=false;
    				}catch(e){}
    			}
            });
    		document.observe('mouseup',function(event){
    			try{
    				self.activeDraggable=false;
    				resizeMarkerLeftTops=false;
	        		var newWidth = parseInt(resizeMarkerRight.getStyle('left')) - parseInt(resizeMarkerLeft.getStyle('left'));
	        		if(resizeMarkerRight.visible() && resizeMarkerLeft.visible()){
		        		setTimeout(function() {
		        			self.ResetCellWidth(sCIndex, newWidth);
		                }, 10);
	        		}
	        		resizeMarkerRight.hide();
	        		resizeMarkerLeft.hide();
    			}catch(e){}
            });
    		document.observe('mousemove',function(event){
    			if(self.activeDraggable){
        			try{
        				Event.stop(event); 
        				var bodyLeft=parseInt($('div_'+self.id).cumulativeOffset().left);
	        			resizeMarkerRight.setStyle({left:(Event.pointerX(event)-bodyLeft)+'px'});
	        			resizeMarkerRight.show();
	        			var newWidth = parseInt(resizeMarkerRight.getStyle('left')) - parseInt(resizeMarkerLeft.getStyle('left'));
        				if(newWidth<10){
        					self.CellShowOrHide(sCIndex,true);
        					$('nk_'+self.id+'_setrow_'+sCIndex+'_setbox').checked=false;
        					$('nk_'+self.id+'_setrow_'+sCIndex).setStyle({color:'#000000',backgroundColor:'#FFFFFF'});
        					self.activeDraggable=false;
            				resizeMarkerLeftTops=false;
        	        		resizeMarkerRight.hide();
        	        		resizeMarkerLeft.hide();
        				}
        			}catch(e){}
        			
    			}
            });
        });
    	//------------------------------------------------------------------------------------------
    	$$('div[id^=nk_'+self.id+'_head_drag_]').each(function(cell){
    		cell.observe('mousedown',function(event){
    			Event.stop(event);
    			var cellIndex=parseInt(cell.id.substring(cell.id.lastIndexOf('_') + 1, cell.id.length));
        		sCIndex=cellIndex;
        		self.activeDraggable=true;
        		resizeMarkerLeftTops=true;
        		
            	var LineHeight=$('nk_'+self.id+'_head_div').getHeight()+$('nk_'+self.id+'_data_div').getHeight();
        		var cellObj=$('nk_'+self.id+'_head_'+sCIndex);
    			var topPos=0;
    	    	if(''!=self.options.title){
    	    		topPos=$('nk_'+self.id+'_title_div').getHeight();
    	    	}
    			try{
    				var cleft=parseInt(parseInt(cellObj.offsetLeft)+parseInt(cellObj.getWidth()))-parseInt(cellObj.cumulativeScrollOffset()[0])-1;
    				resizeMarkerRight.setStyle({left:cleft+'px',top:topPos+'px',height:LineHeight+'px'});
    				resizeMarkerRight.show();
    			}catch(e){}
    			if(resizeMarkerLeftTops){
    				try{
    					var cleft=parseInt(parseInt(cellObj.offsetLeft)-parseInt(cellObj.cumulativeScrollOffset()[0]));
    					resizeMarkerLeft.setStyle({left:cleft+'px',top:topPos+'px',height:LineHeight+'px'});
    					resizeMarkerLeft.show();
    					resizeMarkerLeftTops=false;
    				}catch(e){}
    			}
            });
    		document.observe('mouseup',function(event){
    			try{
    				self.activeDraggable=false;
    				resizeMarkerLeftTops=false;
	        		var newWidth = parseInt(resizeMarkerRight.getStyle('left')) - parseInt(resizeMarkerLeft.getStyle('left'));
	        		if(resizeMarkerRight.visible() && resizeMarkerLeft.visible()){
		        		setTimeout(function() {
		        			self.ResetCellWidth(sCIndex, newWidth);
		                }, 10);
	        		}
	        		resizeMarkerRight.hide();
	        		resizeMarkerLeft.hide();
    			}catch(e){}
            });
    		document.observe('mousemove',function(event){
    			if(self.activeDraggable){
        			try{
        				Event.stop(event); 
        				var bodyLeft=parseInt($('div_'+self.id).cumulativeOffset().left);
	        			resizeMarkerRight.setStyle({left:(Event.pointerX(event)-bodyLeft)+'px'});
	        			resizeMarkerRight.show();
	        			var newWidth = parseInt(resizeMarkerRight.getStyle('left')) - parseInt(resizeMarkerLeft.getStyle('left'));
        				if(newWidth<10){
        					self.CellShowOrHide(sCIndex,true);
        					$('nk_'+self.id+'_setrow_'+sCIndex+'_setbox').checked=false;
        					$('nk_'+self.id+'_setrow_'+sCIndex).setStyle({color:'#000000',backgroundColor:'#FFFFFF'});
        					self.activeDraggable=false;
            				resizeMarkerLeftTops=false;
        	        		resizeMarkerRight.hide();
        	        		resizeMarkerLeft.hide();
        				}
        			}catch(e){}
        			
    			}
            });
        });
    },
    //==========获取单元格的值====================================================================
    cellGetValue : function(body){
    	if(body!==undefined){
    		return $(body.id+'_div').innerHTML.hTrim();
    	}
    	return '';
    },
    //==========获取编辑单元格属性和值=================================================================
    cellGetEditValue : function(body){
    	var self = this;
    	var cellEdit={attribute:'',value:''};
    	if(body!==undefined){
    		try{
	    		var cellidx = self.getRowAndCellIndex(body);//行号和列号
	    		var aids = 'nk_'+self.id+'_attribute_'+cellidx.cellIndex+'_'+cellidx.rowIndex;
	    		var vids = 'nk_'+self.id+'_tdvalue_'+cellidx.cellIndex+'_'+cellidx.rowIndex;
	    		var aid = $(aids).value;
	    		var vid = $(vids).value;
	    		cellEdit.attribute=aid;
	    		cellEdit.value=vid;
    		}catch(e){}
    	}
    	return cellEdit;
    },
    //======================================ajaxinput========================================
    ajaxinputTextCreate : function(body,cfg){//[{type:'input',allownull:'',endeidt,chtype:'',veri:'',msg:'',ismore:'',sql:'',vsql:'',length:''}] vid可以是列号，或列名
    	var self = this;
    	var idx = 0;
        var html = [];
        var id = body.id+'_inputid';
        var name = body.id+'_name';
        var width = body.getWidth()-2;
        var value = self.cellGetValue(body);
        var rcindex = self.getRowAndCellIndex(body);
        try{
	    	var ncfgs = self.tempcellsPars.get(rcindex.cellIndex+'_'+rcindex.rowIndex);
	    	if(undefined !=ncfgs){
	    		Object.extend(cfg, ncfgs);
	    	}
        }catch(e){}
        var allownull = (cfg.allownull==undefined?true:cfg.allownull);
        var chtype = (cfg.chtype==undefined?'':cfg.chtype);
        var verification = (cfg.veri==undefined?'':cfg.veri);
        var msg = (cfg.msg==undefined?'erro mesages for input!':cfg.msg);
        var qulenght=cfg.qulenght;
        var vsql=cfg.vsql;
        var sql=cfg.sql;
        var vid = cfg.vid;
        var ismore= cfg.ismore;
        var miFlg = true;
        var fuFlg = true;
        var row_index = rcindex.rowIndex;//行号
        width=(allownull?width:width-30);
        var rurl = self.url.substring(0,self.url.indexOf('/nokatag'));
        var svalue = value;
        if(undefined!=vid){
        	svalue=self.getCellTd(row_index, vid).innerHTML.hTrim();
        }
        try{
        	setTimeout(function(){
        		$(id+'_input').focus();
        		fuFlg = true;
        	},200);
        }catch(e){}//显示时，设置焦点
        if(value.toLowerCase().indexOf('<div ')==-1){
        	html[idx++]='<div style="top:0px;left:0px;display: none;position: absolute;z-index:99999;overflow: auto;border: 1px solid #AFAFAF;background-color:#FFFFFF;"  id="'+id+'_selectbody"></div>';
    		html[idx++]='<div style="float: left;width:'+width+'px;">';
    		html[idx++]='<input type="hidden" name="'+name+'" id="'+id+'" value="'+svalue+'"/>';
    		html[idx++]='<div style="float: left;display: none;"  id="'+id+'_multinput"></div>';
	        html[idx++]='<div nowrap id="'+id+'_sdDiv" class="nk_input_sdDiv" style="width:'+width+'px">';
	        html[idx++]='<input type="text" id="'+id+'_input" class="nk_input_text" name="'+name+'_input"  style="width:'+width+'px" /></div>';
	        if(!allownull){
	        	html[idx++]='<div style="color: red;float: left;">*</div>';
	        }
	        html[idx++]='<img id="'+id+'_img" style="float:left;"/></div><div nowrap id="'+id+'_div" style="position:absolute;display:none;-moz-border-radius:5px;color:#000000; border-radius:5px;">'+msg+'</div>';
	        html[idx++]='</div>';
	        $(body.id+'_div').innerHTML=html.join('');
			var cfgs = {id:id,chtype:chtype,verification:verification,allownull:allownull,rurl:rurl,qulenght:qulenght,vsql:vsql,sql:sql,ismore:ismore,isGrid:true,showhide:function(a){}};
			var np = new ajaxinputtext(cfgs);
			np.initinput();
        }
       
        $(id+'_input').observe('blur',function(event){//失失焦点时验证其值
        	fuFlg = false;
        	var element = event.element();
        	try{
	        	if($(id).veri() && element.descendantOf($(body.id+'_div'))){
	        		setTimeout(function(){
	        			try{
	        				if(!fuFlg){
	        					var val = $(id).getValues();
	        					if(!self.onEndEdituser(body,cfg.endedit,val.value,val.text)){//单元格对象,事件,值,显示值
									return;
								}
	        					self.keypressEvent();
		 			        	$(body.id+'_div').innerHTML=val.text;
		 			        	if(vid!=undefined){
		 	                		self.getCellTd(row_index, vid).innerHTML=val.value;//实际值
		 	                	}
		 			        	self.setEditCellValue(body,vid);
		 			        	self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+row_index),'edit',$(body.id+'_div'));
	        				}
	        			}catch(e){}
	        		}, 200);
	        	}
        	}catch(e){}
        });
        $(id+'_input').observe('focus',function(event){//输入框得到焦点时验证其值
        	fuFlg = true;
        });
        $(body.id+'_div').observe('mousemove',function(event){
        	try{$(id+'_input').focus();}catch(e){}
        	miFlg = true;
        });
        $(body.id+'_div').observe('mouseout',function(event){
        	miFlg = false;
        	var element = event.element();
        	setTimeout(function(){
        		try{
	                if (element.descendantOf($(body.id+'_div')) && !miFlg && !fuFlg){
	                	if($(id).veri()){
	                		var val = $(id).getValues();
	                		if(!self.onEndEdituser(body,cfg.endedit,val.value,val.text)){//单元格对象,事件,值,显示值
								return;
							}
	                		self.keypressEvent();
	 			        	$(body.id+'_div').innerHTML=val.text;
	 			        	if(vid!=undefined){
	 	                		self.getCellTd(row_index, vid).innerHTML=val.value;//实际值
	 	                	}
	 			        	self.setEditCellValue(body,vid);
		                	self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+row_index),'edit',$(body.id+'_div'));
	                	}
	                }
        		}catch(e){}
            }, 500);
        });
    },
    //=======================================设置编辑值==========================================
    setEditCellValue : function(body,v){
    	var self = this;
    	var cellidx = self.getRowAndCellIndex(body);//行号和列号
    	var ids = 'nk_'+self.id+'_tdvalue_'+cellidx.cellIndex+'_'+cellidx.rowIndex;
    	var vinput = $(ids);
    	try{
    		vinput.value=v;
    	}catch(e){}
    },
    //======================================动态生成minput======================================
    minputTextCreate : function(body,cfg){//[{type:'minput',allownull:'',chtype:'',veri:'',msg:''}] vid可以是列号，或列名
    	var self = this;
    	var idx = 0;
        var html = [];
        var id = body.id+'_inputid';
        var name = body.id+'_name';
        var width = body.getWidth()-20;
        var value = self.cellGetValue(body);
        var rcindex = self.getRowAndCellIndex(body);
        try{
	    	var ncfgs = self.tempcellsPars.get(rcindex.cellIndex+'_'+rcindex.rowIndex);
	    	if(undefined !=ncfgs){
	    		Object.extend(cfg, ncfgs);
	    	}
        }catch(e){}
        var allownull = (cfg.allownull==undefined?true:cfg.allownull);
        var chtype = (cfg.chtype==undefined?'':cfg.chtype);
        var verification = (cfg.veri==undefined?'':cfg.veri);
        var msg = (cfg.msg==undefined?'erro mesages for input!':cfg.msg);
        var miFlg = true;
        var fuFlg = true;
        var row_index = rcindex.rowIndex;//行号
        width=(allownull?width:width-30);
        var rurl = self.url.substring(0,self.url.indexOf('/nokatag'));
        try{setTimeout(function(){$(id+'_input').focus();fuFlg = true;},200);}catch(e){}//显示时，设置焦点
        if(value.toLowerCase().indexOf('<div ')==-1){
    		html[idx++]='<div style="float: left;">';
    		html[idx++]='<input type="hidden" name="'+name+'" id="'+id+'" value="'+value+'"/>';
    		html[idx++]='<div style="float: left;display: none;"  id="'+id+'_multinput"></div>';
    		html[idx++]='<div id='+id+'_maxDiv"  style="position:absolute;-moz-border-radius:5px; border-radius:5px;"></div>';
	        html[idx++]='<div nowrap id="'+id+'_sdDiv" class="nk_input_sdDiv" style="width:'+width+'px">';
	        html[idx++]='<input type="text" id="'+id+'_input" name="'+name+'_input" class="nk_input_lineheight nk_input_text" style="width:'+width+'px" value="'+value+'"/></div>';
	        if(!allownull){
	        	html[idx++]='<div style="color: red;float: left;" class="nk_input_lineheight">*</div>';
	        }
	        html[idx++]='<img id="'+id+'_img" style="float:left;" class="nk_input_imgheight"/></div><div class="nk_input_message" nowrap id="'+id+'_div" style="position:absolute;display:none;">'+msg+'</div>';
	        html[idx++]='</div>';
	        $(body.id+'_div').innerHTML=html.join('');
			var cfgs = {id:id,chtype:chtype,verification:verification,allownull:allownull,rurl:rurl};
			var np = new multinputtext(cfgs);
			np.initinput();
        }
        $(id+'_input').observe('blur',function(event){//失失焦点时验证其值
        	fuFlg = false;
        	var element = event.element();
        	try{
	        	if($(id).veri() && element.descendantOf($(body.id+'_div'))){
	        		setTimeout(function(){
	        			try{
	        				if(!fuFlg){
	        					var inpu_value=$(id).value;//显示值附给当前列
	        					if(!self.onEndEdituser(body,cfg.endedit,inpu_value)){//单元格对象,事件
									return;
								}
		 			        	$(body.id+'_div').innerHTML=inpu_value;
		 			        	self.setEditCellValue(body,inpu_value);
		 			        	self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+row_index),'edit',$(body.id+'_div'));
	        				}
	        			}catch(e){}
	        		}, 200);
	        	}
        	}catch(e){}
        });
        $(id+'_input').observe('focus',function(event){//输入框得到焦点时验证其值
        	fuFlg = true;
        });
        $(body.id+'_div').observe('mousemove',function(event){
        	try{$(id+'_input').focus();}catch(e){}
        	miFlg = true;
        });
        $(body.id+'_div').observe('mouseout',function(event){
        	miFlg = false;
        	var element = event.element();
        	setTimeout(function(){
        		try{
	                if (element.descendantOf($(body.id+'_div')) && !miFlg && !fuFlg){
	                	if($(id).veri()){
	                		var inpu_value=$(id).value;//显示值附给当前列
	                		if(!self.onEndEdituser(body,cfg.endedit,inpu_value)){//单元格对象,事件
								return;
							}
		                	$(body.id+'_div').innerHTML=inpu_value;
		                	self.setEditCellValue(body,inpu_value);
		                	self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+row_index),'edit',$(body.id+'_div'));
	                	}
	                }
        		}catch(e){}
            }, 500);
        });
    },
    //======================================动态生成开关按钮=======================================
    nswitch : function(body,cfg){//[{type:'input',allownull:'',chtype:'',veri:'',msg:''}] vid可以是列号，或列名
    	var self = this;
    	var idx = 0;
        var html = [];
        var sid = body.id+'_inputid';
        var sname = body.id+'_name';
        var swidth = body.getWidth()-2;
        var svalue = self.cellGetValue(body);
        var vid = cfg.vid;
        //-----------------------自定义参数--------------------------------------------------
        var rcindex = self.getRowAndCellIndex(body);
        try{
	    	var ncfgs = self.tempcellsPars.get(rcindex.cellIndex+'_'+rcindex.rowIndex);
	    	if(undefined !=ncfgs){
	    		Object.extend(cfg, ncfgs);
	    	}
        }catch(e){}
        var row_index = rcindex.rowIndex;//行号
        if(svalue.toLowerCase().indexOf('<div ')==-1){
        	html[idx++]='<div id="'+sid+'_div" style="float: left;width:'+swidth+'px" class="noka_switch nk_input_sdDiv"></div>';
        	$(body.id+'_div').innerHTML=html.join('');
	        var rurl = self.url.substring(0,self.url.indexOf('/nokatag'));
	        var bvalue = (undefined==self.getCellTd(row_index, vid).innerHTML?'':self.getCellTd(row_index, vid).innerHTML.hTrim());
	        if(undefined==cfg.open){
	        	cfg.open = {title:'YES',value:'1'};
	        }
	        if(undefined==cfg.off){
	        	cfg.off = {title:'OFF',value:'0'};
	        }
	        if(cfg.open.value==bvalue){
	        	bvalue = cfg.off.value;
	        }else{
	        	bvalue = cfg.open.value;
	        }
			var cfgs = {
					id:sid,
					name:sname,
					value:svalue,
					width:(swidth/2-10),
					off:cfg.off,
					open:cfg.open,
					value:bvalue,
					rurl:rurl
					};
			var np = new nswitch(cfgs);
			np.show();
        }
        $(body.id+'_div').observe('mousemove',function(event){
        	miFlg = true;
        });
        $(body.id+'_div').observe('mouseout',function(event){
        	miFlg = false;
        	var element = event.element();
        	setTimeout(function(){
                if (element.descendantOf($(body.id+'_div')) && !miFlg){
                	var show_value=$(sid+'_sinput').value;//显示值附给当前列
                	var inpu_value=$(sid).value;//显示值附给当前列
                	if(!self.onEndEdituser(body,cfg.endedit,inpu_value,show_value)){//单元格对象,事件
						return;
					}
                	$(body.id+'_div').setStyle({overflow:'hidden'});
                	$(body.id+'_div').innerHTML=show_value;
                	if(vid!=undefined){
                		self.getCellTd(row_index, vid).innerHTML=inpu_value;//实际值
                	}
                	self.setEditCellValue(body,inpu_value);
                	self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+row_index),'edit',$(body.id+'_div'));
                }
            }, 500);
        });
    },
    //======================================动态生成input=======================================
    inputTextCreate : function(body,cfg){//[{type:'input',allownull:'',chtype:'',veri:'',msg:''}] vid可以是列号，或列名
    	var self = this;
    	var idx = 0;
        var html = [];
        var id = body.id+'_inputid';
        var name = body.id+'_name';
        var width = body.getWidth()-2;
        var value = self.cellGetValue(body);
        //-----------------------自定义参数--------------------------------------------------
        var rcindex = self.getRowAndCellIndex(body);
        try{
	    	var ncfgs = self.tempcellsPars.get(rcindex.cellIndex+'_'+rcindex.rowIndex);
	    	if(undefined !=ncfgs){
	    		Object.extend(cfg, ncfgs);
	    	}
        }catch(e){}
        var allownull = (cfg.allownull==undefined?true:cfg.allownull);
        var chtype = (cfg.chtype==undefined?'':cfg.chtype);
        var verification = (cfg.veri==undefined?'':cfg.veri);
        var msg = (cfg.msg==undefined?'erro mesages for input!':cfg.msg);
        var miFlg = true;
        var fuFlg = true;
        var row_index = rcindex.rowIndex;//行号
        width=(allownull?width:width-30);
        try{setTimeout(function(){$(id).focus();},300);}catch(e){}//显示时，设置焦点
        if(value.toLowerCase().indexOf('<div ')==-1){
    		html[idx++]='<div style="float: left;">';
	        html[idx++]='<div nowrap id="'+id+'_sdDiv" class="nk_input_sdDiv"  style="width:'+width+'">';
	        html[idx++]='<input type="text" id="'+id+'" class="nk_input_lineheight nk_input_text" name="'+name+'"  style="width:'+width+'" value="'+value+'"/></div>';
	        if(!allownull){
	        	html[idx++]='<div style="color: red;float: left;" class="nk_input_lineheight">*</div>';
	        }
	        html[idx++]='<img id="'+id+'_img" style="float:left;" class="nk_input_imgheight"/></div><div nowrap class="nk_input_message" id="'+id+'_div" style="position:absolute;display:none;">'+msg+'</div>';
	        html[idx++]='</div>';
	        $(body.id+'_div').innerHTML=html.join('');
	        var rurl = self.url.substring(0,self.url.indexOf('/nokatag'));
			var cfgs = {id:id,chtype:chtype,verification:verification,allownull:allownull,rurl:rurl};
			var np = new ninput(cfgs);
			np.initinput();
        }
        $(id).observe('blur',function(event){//失失焦点时验证其值
        	fuFlg = false;
        	try{
	        	if($(id).veri()){
	        		 var inpu_value=$(id).value;//显示值附给当前列
	        		if(!self.onEndEdituser(body,cfg.endedit,inpu_value)){//单元格对象,事件
						return;
					}
			        $(body.id+'_div').innerHTML=inpu_value;
			        self.setEditCellValue(body,inpu_value);
			        self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+row_index),'edit',$(body.id+'_div'));
	        	}
        	}catch(e){}
        });
        $(id).observe('focus',function(event){//输入框得到焦点时验证其值
        	fuFlg = true;
        });
        $(body.id+'_div').observe('mousemove',function(event){
        	try{$(id).focus();}catch(e){}
        	miFlg = true;
        });
        $(body.id+'_div').observe('mouseout',function(event){
        	miFlg = false;
        	var element = event.element();
        	setTimeout(function(){
        		try{
	                if (element.descendantOf($(body.id+'_div')) && !miFlg && !fuFlg){
	                	if($(id).veri()){
	                		var inpu_value=$(id).value;//显示值附给当前列
	                		if(!self.onEndEdituser(body,cfg.endedit,inpu_value)){//单元格对象,事件
								return;
							}
		                	$(body.id+'_div').innerHTML=inpu_value;
		                	self.setEditCellValue(body,inpu_value);
		                	self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+row_index),'edit',$(body.id+'_div'));
	                	}
	                }
        		}catch(e){}
            }, 500);
        });
    },
    //===============================下拉框===================================================
    selectCreate : function(body,cfg){//[{type:'select',vid:'',json:'',sql:'',allownull:''}] vid可以是列号，或列名
    	var self = this;
    	var idx = 0;
        var html = [];
        var id = body.id+'_selectid';
        var name = body.id+'_name';
        var width = body.getWidth();
        var value = self.cellGetValue(body);
        //-----------------------自定义参数--------------------------------------------------
        var rcindex = self.getRowAndCellIndex(body);
    	var cfgs = self.tempcellsPars.get(rcindex.cellIndex+'_'+rcindex.rowIndex);
    	if(undefined !=cfgs){
    		Object.extend(cfg, cfgs);
    	}
        var json = (cfg.json==undefined?'':cfg.json);//[{text:'aaaa',value:'fff'}]
        var sql = (cfg.sql==undefined?'':cfg.sql);
        var vid = cfg.vid;
        var allownull = (cfg.allownull==undefined?true:cfg.allownull);
        var miFlg = true;
        var row_index = rcindex.rowIndex;//行号
        var ptopLower = (undefined==cfg.topLower?[]:cfg.topLower);
    	if(!allownull){
    		width=width-10;
    	}
    	var lower =(cfg.lower==undefined?'':cfg.lower);
    	//-------------------------------------------------------------------------------
        if(value.toLowerCase().indexOf('<div ')==-1){
	        html[idx++]='<div id="'+id+'_sDiv">';
	        html[idx++]='<div id="'+id+'_selectDiv" style="float:left;"></div>';
	        html[idx++]='<div id="'+id+'_sboddiv"  style="width:'+(width)+'px;z-index:9999;background-color: #fff;display:none;position:absolute;overflow-x:hidden;height:100px;top:0px;left:0px;border: 1px solid #ddd;"></div>';
	        html[idx++]='</div>';
	        $(body.id+'_div').innerHTML=html.join('');
	        var rurl = self.url.substring(0,self.url.indexOf('/nokatag'));
	        var sfg = {
	        		id:id,
	        		rurl:rurl,
	        		slang:self.lanage.Lanage_slang,
	        		name:name,
	        		lower:lower,
	        		json:json,
	        		height:'100',
	        		value:(undefined==self.getCellTd(row_index, vid).innerHTML?'':self.getCellTd(row_index, vid).innerHTML.hTrim()),
	        		readonly:'',
	        		allownull:allownull,
	        		placeholder:'',
	        		onchange:function(node){return true;},
	        		width:width,
	        		sql:sql,
	        		topLower:ptopLower
	        	};
	        var nr = new nselect(sfg);
	        nr.show();
	        $(body.id+'_div').setStyle({overflow:''});
        }
        $(body.id+'_div').observe('mousemove',function(event){
        	miFlg = true;
        });
        $(body.id+'_div').observe('mouseout',function(event){
        	miFlg = false;
        	var element = event.element();
        	setTimeout(function(){
                if (element.descendantOf($(body.id+'_div')) && !miFlg){
                	var show_value=$(id+'_sinput').value;//显示值附给当前列
                	var inpu_value=$(id).value;//显示值附给当前列
                	if(!self.onEndEdituser(body,cfg.endedit,inpu_value,show_value)){//单元格对象,事件
						return;
					}
                	$(body.id+'_div').setStyle({overflow:'hidden'});
                	$(body.id+'_div').innerHTML=show_value;
                	if(vid!=undefined){
                		self.getCellTd(row_index, vid).innerHTML=inpu_value;//实际值
                	}
                	self.setEditCellValue(body,inpu_value);
                	self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+row_index),'edit',$(body.id+'_div'));
                }
            }, 500);
        });
    },
    //========================下拉多选=======================================
    selectMultiCreate : function(body,cfg){//[{type:'selectmulti',vid:'',json:'',sql:'',allownull:''}] vid可以是列号，或列名
    	var self = this;
    	var idx = 0;
        var html = [];
        var id = body.id+'_selectmuid';
        var name = body.id+'_name';
        var width = body.getWidth();
        var value = self.cellGetValue(body);
        var rcindex = self.getRowAndCellIndex(body);
        var cfgs = self.tempcellsPars.get(rcindex.cellIndex+'_'+rcindex.rowIndex);
    	if(undefined !=cfgs){
    		Object.extend(cfg, cfgs);
    	}
        var json = (cfg.json==undefined?'':cfg.json);//[{text:'aaaa',value:'fff'}]
        var sql = (cfg.sql==undefined?'':cfg.sql);
        var vid = cfg.vid;
        var allownull = (cfg.allownull==undefined?true:cfg.allownull);
        var miFlg = true;
        var row_index = rcindex.rowIndex;//行号
    	if(!allownull){
    		width=width-28;
    	}
        if(value.toLowerCase().indexOf('<div ')==-1){
	        html[idx++]='<div id="'+id+'_sDiv">';
	        html[idx++]='<div id="'+id+'_selectDiv" style="float:left;"></div>';
	        html[idx++]='<div id="'+id+'_sboddiv"  style="width:'+(width)+'px;z-index:9999;background-color: #fff;display:none;position:absolute;overflow-x:hidden;height:100px;top:0px;left:0px;border: 1px solid #ddd;"></div>';
	        html[idx++]='</div>';
	        $(body.id+'_div').innerHTML=html.join('');
	        var rurl = self.url.substring(0,self.url.indexOf('/nokatag'));
	        var sfg = {
	        		id:id,
	        		rurl:rurl,
	        		slang:self.lanage.Lanage_slang,
	        		name:name,
	        		lower:'',
	        		json:json,
	        		height:'100',
	        		value:(undefined==self.getCellTd(row_index, vid).innerHTML?'':self.getCellTd(row_index, vid).innerHTML.hTrim()),
	        		readonly:'',
	        		allownull:allownull,
	        		placeholder:'',
	        		onchange:function(node){return true;},
	        		width:width,
	        		sql:sql
	        		};
	        var nr = new nselectmulti(sfg);
	        nr.show();
	        $(body.id+'_div').setStyle({overflow:''});
        }
        $(body.id+'_div').observe('mousemove',function(event){
        	miFlg = true;
        });
        $(body.id+'_div').observe('mouseout',function(event){
        	miFlg = false;
        	var element = event.element();
        	setTimeout(function(){
                if (element.descendantOf($(body.id+'_div')) && !miFlg && $(id).veri()){
                	var show_value=$(id+'_sinput').value;//显示值附给当前列
                	var inpu_value=$(id).value;//显示值附给当前列
                	if(!self.onEndEdituser(body,cfg.endedit,inpu_value,show_value)){//单元格对象,事件
						return;
					}
                	$(body.id+'_div').setStyle({overflow:'hidden'});
                	$(body.id+'_div').innerHTML=show_value;
                	if(vid!=undefined){
                		self.getCellTd(row_index, vid).innerHTML=inpu_value;//实际值
                	}
                	self.setEditCellValue(body,inpu_value);
                	self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+row_index),'edit',$(body.id+'_div'));
                }
            }, 500);
        });
    },
    //============================时间 日期选择框=================================================
    DateSelectCreate : function(body,cfg){//[{type:'date',dateFmt,allownull}] 
    	var self = this;
    	var idx = 0;
        var html = [];
        var id = body.id+'_dateid';
        var name = body.id+'_name';
        var width = body.getWidth();
        var value = self.cellGetValue(body);
        var rcindex = self.getRowAndCellIndex(body);
        try{
	    	var ncfgs = self.tempcellsPars.get(rcindex.cellIndex+'_'+rcindex.rowIndex);
	    	if(undefined !=ncfgs){
	    		Object.extend(cfg, ncfgs);
	    	}
        }catch(e){}
        var dateFmt =(cfg.dateFmt==undefined?'yyyy-MM-dd':cfg.dateFmt);
        var allownull = (cfg.allownull==undefined?true:cfg.allownull);
    	var rurl=self.url.substring(0,self.url.indexOf('/nokatag'));
    	if(!allownull){
    		width=width-30;
    	}
        var row_index = rcindex.rowIndex;//行号
        if(value.toLowerCase().indexOf('<div ')==-1){
        	html[idx++]='<div  style="float: left;">';
        	html[idx++]='<div  class="date-dropdownchecklist nk_input_lineheight nk_input_sdDiv"  id="'+id+'_sdDiv" style="width:'+width+'px;float: left;">';
        	html[idx++]='<input type="text" id="'+id+'" name="'+name+'" class="nk_input_lineheight nk_select_input_text" style="width:'+(width-18)+'px;" value="'+value+'"/>';
        	html[idx++]='</div>';
        	html[idx++]='<div id="'+id+'_dadiv" style="float: left;">';
        	if(!allownull){
            	html[idx++] = '<div style="float:left;color: red;"  class="nk_input_lineheight">*</div>';
            	html[idx++] = '<img style="display:none;vertical-align:middle" class="nk_input_imgheight" id="'+id+'_img" src="'+rurl+'/nokatag/formcheck/images/exclamation.gif"></img>';
            }
        	html[idx++]='</div>';
        	html[idx++]='</div>';
        	$(body.id+'_div').innerHTML=html.join('');
        	$(id+'_sdDiv').observe('click',function(event){
        		WdatePicker({el:id, dateFmt:dateFmt,
        			onpicked:function(){
        				var dvalue = $(id).value;
        				if(!self.onEndEdituser(body,cfg.endedit,dvalue)){//单元格对象,事件
							return;
						}
        				try{$(body.id+'_div').innerHTML=dvalue;}catch(e){}
        				self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+row_index),'edit',$(body.id+'_div'));
        			},onHideDate:function(){
        				if($(id).value.trim().length<1 && !allownull){//不能为空
        					$(id+'_img').show();
        				}else{
        					var dvalue = $(id).value;
        					if(!self.onEndEdituser(body,cfg.endedit,dvalue)){//单元格对象,事件
    							return;
    						}
            				$(body.id+'_div').innerHTML=dvalue;
            				self.setEditCellValue(body,dvalue);
            				self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+row_index),'edit',$(body.id+'_div'));
        				}
        			},oncleared:function(){
        				if($(id).value.trim().length<1 && !allownull){//不能为空
        					$(id+'_img').show();
        				}else{
        					var dvalue = $(id).value;
        					if(!self.onEndEdituser(body,cfg.endedit,dvalue)){//单元格对象,事件
    							return;
    						}
            				$(body.id+'_div').innerHTML=dvalue;
            				self.setEditCellValue(body,dvalue);
            				self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+row_index),'edit',$(body.id+'_div'));
        				}
        			}
        			});
        	});
        }
    },
    //===========================树形下拉框====================================================
    ntreeSelectCreate : function(body,cfg){//[{type:'treeselect',vid:'',sid:'',level:'',sql:'',allownull,checktype}] vid可以是列号，或列名
    	var self = this;
    	var idx = 0;
        var html = [];
        var id = body.id+'_treeid';
        var name = body.id+'_name';
        var width = body.getWidth();
        var svalue = self.cellGetValue(body);//显示值
        var rcindex = self.getRowAndCellIndex(body);
        try{
	    	var ncfgs = self.tempcellsPars.get(rcindex.cellIndex+'_'+rcindex.rowIndex);
	    	if(undefined !=ncfgs){
	    		Object.extend(cfg, ncfgs);
	    	}
        }catch(e){}
        var miFlg = true;
        var sid = (cfg.sid==undefined?'-1':cfg.sid);
        var sql = cfg.sql;//加密后的sql
        var vid = cfg.vid;
        var clevel = (undefined!=cfg.level?cfg.level:1);
        var row_index = rcindex.rowIndex;//行号
    	var allownull =  (cfg.allownull==undefined?true:cfg.allownull);
    	var checktype =  (cfg.checktype==undefined?'':cfg.checktype);
    	var cfgp = cfg;
    	var stitllev = cfg.titllev;
    	if(!allownull){
    		width=width-24;
    	}
        if(svalue.toLowerCase().indexOf('<div ')==-1){
        	html[idx++]='<div id="'+id+'_bdiv">';
        	html[idx++]='<div id="'+id+'_sdiv" class="dtree" style="float:left;"></div>';
        	html[idx++]='<div id="'+id+'_tdiv" class="dtree" style="z-index: 999;background-color: #fff;display:none;position:absolute;overflow:auto;top:0px;left:0px;border: 1px solid #ddd;"></div>';
        	html[idx++]='</div>';
        	$(body.id+'_div').innerHTML=html.join('');
        	var rurl = self.url.substring(0,self.url.indexOf('/nokatag'));
        	var cfgs = {
    		id:id,
    		rurl:rurl,
    		slang:self.lanage.Lanage_slang,
    		url:'',
    		level:2,
    		spid:sid,
    		sql:sql,
    		pramevar:'',
    		target:'',
    		formatcell:'',
    		inputname:name,
    		checkname:id+'_check',
    		level:clevel,
    		value:(undefined==self.getCellTd(row_index, vid).innerHTML?'':self.getCellTd(row_index, vid).innerHTML.hTrim()),
    		readonly:'',
    		titlecliek:true,
    		allownull:allownull,
    		titllev:stitllev,
    		placeholder:'',
    		width:(width-18),
    		height:300,
    		checktype:checktype,
    		titleonclick:function(node){},
    		nodeonclick:function(node){},
    		checkboxonclick:function(node){return true;}
    		};
        	var nr = new ntree(cfgs);
    		nr.selectShow();
    		$(body.id+'_div').setStyle({overflow:''});
        }
        $(body.id+'_div').observe('mousemove',function(event){
        	miFlg = true;
        });
        $(body.id+'_div').observe('mouseout',function(event){
        	miFlg = false;
        	var element = event.element();
        	setTimeout(function(){
                if (element.descendantOf($(body.id+'_div')) && !miFlg && $(id).veri()){
                	var show_value=$(id+'_sinput').value;//显示值附给当前列
                	var inpu_value=$(id).value;//显示值附给当前列
                	if(!self.onedituser(body,cfgp.endedit,inpu_value,show_value)){//单元格对象,事件
						return;
					}
                	$(body.id+'_div').setStyle({overflow:'hidden'});
                	$(body.id+'_div').innerHTML=show_value;
                	if(vid!=undefined){
                		self.getCellTd(row_index, vid).innerHTML=inpu_value;//实际值
                	}
                	self.setEditCellValue(body,inpu_value);
                	self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+row_index),'edit',$(body.id+'_div'));
                }
            }, 500);
        });
    },
    //=================横向树形下拉框======================================
    treeTranSelect : function(body,cfg){//[{type:'treeselect',vid:'',sid:'',level:'',sql:'',allownull,checktype}] vid可以是列号，或列名
    	var self = this;
    	var idx = 0;
        var html = [];
        var id = body.id+'_treeid';
        var name = body.id+'_name';
        var width = body.getWidth();
        var svalue = self.cellGetValue(body);//显示值
        var miFlg = true;
        var rcindex = self.getRowAndCellIndex(body);
        try{
	    	var ncfgs = self.tempcellsPars.get(rcindex.cellIndex+'_'+rcindex.rowIndex);
	    	if(undefined !=ncfgs){
	    		Object.extend(cfg, ncfgs);
	    	}
        }catch(e){}
        var sid = (cfg.sid==undefined?'-1':cfg.sid);
        var sql = cfg.sql;//加密后的sql
        var vid = cfg.vid;
        var row_index = rcindex.rowIndex;//行号
    	var allownull =  (cfg.allownull==undefined?true:cfg.allownull);
    	var checktype =  (cfg.checktype==undefined?false:cfg.checktype);
    	var slower = (cfg.lower==undefined?'':cfg.lower);
    	var stitleonclick = (cfg.titleonclick==undefined?function(a,b){}:cfg.titleonclick);
    	var snodeonclick= (cfg.nodeonclick==undefined?function(a,b){}:cfg.nodeonclick);
    	var scheckboxonclick= (cfg.checkboxonclick==undefined?function(a,b){}:cfg.checkboxonclick);
    	var cfgp = cfg;
    	var stitllev = cfg.titllev;
    	if(!allownull){
    		width=width-24;
    	}
    	//var sbwidth  = (cfg.bwidth==undefined?width:cfg.bwidth);
        if(svalue.toLowerCase().indexOf('<div ')==-1){
        	html[idx++]='<div id="'+id+'_bdiv">';
        	html[idx++]='<div id="'+id+'_sdiv" class="trandtree" style="float:left;"></div>';
        	html[idx++]='<div id="'+id+'_tdiv" class="trandtree" style="z-index: 999;background-color: #fff;display:none;position:absolute;overflow:auto;top:0px;left:0px;border: 1px solid #ddd;"></div>';
        	html[idx++]='</div>';
        	$(body.id+'_div').innerHTML=html.join('');
        	var rurl = self.url.substring(0,self.url.indexOf('/nokatag'));
        	var cfg = {
    		id:id,
    		rurl:rurl,
    		slang:self.lanage.Lanage_slang,
    		sclose:self.lanage.Lanage_sclose,
    		sclear:self.lanage.Lanage_sclear,
    		url:'',
    		spid:sid,
    		sql:sql,
    		pramevar:'',
    		target:'',
    		formatcell:'',
    		inputname:name,
    		value:(undefined==self.getCellTd(row_index, vid).innerHTML?'':self.getCellTd(row_index, vid).innerHTML.hTrim()),
    		readonly:'',
    		allownull:allownull,
    		titllev:stitllev,
    		lower:slower,
    		placeholder:'',
    		width:(width-18),
    		checktype:checktype,
    		titleonclick:function(obj,node){stitleonclick(obj,node);},
    		nodeonclick:function(obj,node){snodeonclick(obj,node);},
    		checkboxonclick:function(obj,node){scheckboxonclick(obj,node);}
    		};
        	var nr = new ntreetran(cfg);
    		nr.selectShow();
    		$(body.id+'_div').setStyle({overflow:''});
        }
        $(body.id+'_div').observe('mousemove',function(event){
        	miFlg = true;
        });
        $(body.id+'_div').observe('mouseout',function(event){
        	miFlg = false;
        	var element = event.element();
        	setTimeout(function(){
                if (element.descendantOf($(body.id+'_div')) && !miFlg && $(id).veri()){
                	var show_value=$(id+'_sinput').value;//显示值附给当前列
                	var inpu_value=$(id).value;//显示值附给当前列
                	if(!self.onedituser(body,cfgp.endedit,inpu_value,show_value)){//单元格对象,事件
						return;
					}
                	$(body.id+'_div').setStyle({overflow:'hidden'});
                	$(body.id+'_div').innerHTML=show_value;
                	if(vid!=undefined){
                		self.getCellTd(row_index, vid).innerHTML=inpu_value;//实际值
                	}
                	self.setEditCellValue(body,inpu_value);
                	self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+row_index),'edit',$(body.id+'_div'));
                }
            }, 500);
        });
    },
    //----------------在编辑时，实时提交数据----------------------------------
    editAjaxSubmit : function(row,doty,EditCell){
    	var self = this;
    	var idx = 0;
    	var pars=[];//提交参数
    	var cells = row.cells;
    	var editAction=self.endtSubmitAction;
    	var isAdd=self.editAddNowHash.unset(row.id);//是否新增行
    	if(isAdd){
    		doty='add';
    	}
    	if(editAction==undefined){//不开启编辑提交功能
    		return;
    	}
    	//---------组织行参数----------------------------------------
    	pars[idx++]='&doty='+doty;
    	if(self.showcell){
    		 var cvs = $(row.id+'_json').innerHTML.evalJSON();
    		 for(var i=0;i<cvs.length;i++){
    			 pars[idx++]='&c_'+(i+1)+'='+encodeURIComponent(cvs[i]);
    		 }
    	}else{//行模式组织参数
			for(var i=self.syscells.length;i<cells.length;i++){
				var rdv = self.cellGetValue(cells[i]);
				var edv = self.cellGetEditValue(cells[i]);//编辑对象
				if(rdv.indexOf('<div ')==-1){
					if(edv.attribute!=''){
						pars[idx++]='&'+edv.attribute+'='+encodeURIComponent(edv.value);
					}else{
						var cindex = i-self.syscells.length;
						pars[idx++]='&c_'+(cindex+1)+'='+encodeURIComponent(rdv);
					}
				}
			}
    	}
		if(EditCell!=undefined){
 		   EditCell.setStyle({backgroundColor:self.editSubmitColor.loadColor});//设置正在提交色
 	    }
		try{
			var userOnSubmit = self.editOnSubmit(self.RowCreateFunction(row));
			if(userOnSubmit!=undefined){
				if(!userOnSubmit.submit){//外部返回为false，不允许提交
					return;
				}
				if(userOnSubmit.data!=undefined){//有自定义数据
					var pdata = userOnSubmit.data;
					for(var c=0;c<pdata.length;c++){
						pars[idx++]='&'+pdata[c].name+'='+encodeURIComponent(pdata[c].value);
					}
				}
			}
		}catch(e){}
		//---------提交数据-----------------------------------------
		if(self.getInputVri(row.id)){
			new Ajax.Request(editAction, {
			    parameters: pars.join(''),
			           method:'post',
			           onSuccess: function(response) {
			        	   try{
			        		   var reJSON = response.responseText.evalJSON();//以json格式返回{run:true,rdata:[{cell:'',value:''}],aaaa:{}}
			        		   var rowobj = self.RowCreateFunction(row);
			        		   if(reJSON!=undefined && reJSON.run!=undefined){
			        			   if(reJSON.run && EditCell!=undefined){//后台处理成功,并且是单元格编辑操作
			        				   EditCell.setStyle({backgroundColor:self.editSubmitColor.successColor});//编辑成功，恢复本色
			        				   try{
				        				   if(reJSON.rdata!=undefined){//更新行数据
				        					   var rdata = reJSON.rdata;
				        					   for(var s=0;s<rdata.length;s++){
				        						   if(rdata[s].cell=='check'){//选择框
				        							   rowobj.getCheck().value=rdata[s].value;
				        						   }else{
				        							   rowobj.getCell(rdata[s].cell).setValue(rdata[s].value);
				        						   }
				        					   }
				        				   }
			        				   }catch(e){}
			        			   }else{//后台处理失败
			        				   EditCell.setStyle({backgroundColor:self.editSubmitColor.failureColor});//编辑失败，设置醒目色
			        			   }
			        		   }
			        		   self.editOnReturn(rowobj,reJSON);
			        	   }catch(e){}
			           },
			           onFailure : function(response) {
			        	   if(EditCell!=undefined){
			        		   EditCell.setStyle({backgroundColor:self.editSubmitColor.failureColor});//编辑失败，设置醒目色
			        		   self.editOnReturn(self.RowCreateFunction(row),reJSON);
			        	   }
			           }
			});
		}
    },
    //------------提交所有数据---------------------------------------------
    editAjaxSubmitAll : function(a,asynchronou){
    	var self = this;
    	var editAction = self.editAllSubmitAction;
    	var rdata = self.getGridData();//获取所有数据
    	var pars = [];
    	var idx=0;
    	pars[idx++]='nokardata='+encodeURIComponent(rdata.toJSON());//表格数据
    	//--------------外部方法数据--------------------------------------
    	try{
			var userOnSubmit = self.editOnSubmitAll(rdata);
			if(userOnSubmit!=undefined){
				if(!userOnSubmit.submit){//外部返回为false，不允许提交
					return;
				}
				if(userOnSubmit.data!=undefined){//有自定义数据
					var pdata = userOnSubmit.data;
					for(var i=0;i<pdata.length;i++){
						pars[idx++]='&'+pdata[i].name+'='+encodeURIComponent(pdata[i].value);//用户数据
					}
				}
			}
		}catch(e){}
		//--------------外部表单数据----------------------------------------
		try{
			if(undefined !=self.editOnSubmitForm){
				var formpars = self.GetFormPars(self.editOnSubmitForm);
				if(formpars.vri){
					pars[idx++]=formpars.data;
				}else{
					return;
				}
			}
		}catch(e){}
    	editAction=(a!=undefined?a:editAction);
    	if(self.getInputVri()){//合法性验证
	    	new Ajax.Request(editAction, {
			    parameters:pars.join(''),
			    method:'post',
			    asynchronous:(undefined==asynchronou?true:asynchronou),//是否异步提交
			    onSuccess: function(response) {
	            	try{
	            		self.options.onsuccess(response);
	            	}catch(e){}
	            },
	            onFailure : function(response) {
	            	self.options.onfailure(response);
	            }
			});
    	}
    },
    //------------------------根据列号或列名，获取单元格对像---------------------
    getCellTd : function(rowIndex,vid){
    	if(vid!==undefined){
	    	var self = this;
	    	var vcell_index = self.cellNameToIndex(vid);//根据列名找到列号
			return $('nk_'+self.id+'_dcell_'+vcell_index+'_'+rowIndex+'_div');
    	}
    	return {};
    },
    //------------------------获取行号，列号-------------------------------
    getRowAndCellIndex : function(body){
    	var row_index = body.id.substring(body.id.lastIndexOf('_')+1,body.id.length);//行号
    	var start_index = body.id.indexOf('dcell_')+'dcell_'.length;
    	var stop_index = body.id.lastIndexOf('_'+row_index);
    	var cel_index = body.id.substring(start_index,stop_index);//列号
    	var reObject = {rowIndex:row_index,cellIndex:cel_index};
    	return reObject;
    },
    //------------根据序号找到对应的列名---------------------------------------
    cellIndexToName : function(index){
    	var self = this;
    	try{
    		var midex = parseInt(index)-parseInt(self.syscells.length);
    		return self.columnModel[midex].name;
    	}catch(e){}
    	return '';
    },
    //------------------------根据行号获取行对象-----------------------------
    getRowObject : function(rowindx){
    	var self = this;
    	return $('nk_'+self.id+'_dcell_'+rowindx);
    },
    getRowLeftObject : function(rowindx){
    	var self = this;
    	return $('nk_'+self.id+'_left_dcell_'+rowindx);
    },
    //------------------------根据单元格对象获取行对象-------------------------
    getRowTd : function(body){
    	var self = this;
    	var rowIndex = self.getRowAndCellIndex(body).rowIndex;
    	return $('nk_'+self.id+'_dcell_'+rowIndex);
    },
    //-----------根据对应的列号找到对应的编辑属性---------------------------------
    getEditAttribute : function(index){
    	var self = this;
    	var midex = parseInt(index)-parseInt(self.syscells.length);
    	var cellName = self.columnModel[midex].title;//列名
    	var editCells = self.editCells;//编辑[{cell:'MENUID',attribute:'',cfg:{type:'input':'',allownull:false}},{cell:'MENUID2',cfg:{type:'input',allownull:false}}]
    	if(undefined!=editCells && editCells.length>0){
    	for(var i=0;i<editCells.length;i++){
    		var attribute = editCells[i].attribute;
    		var cell = editCells[i].cell;
    		if((undefined != cell) && (cell==cellName || index==cell) && (undefined != attribute) ){
    			return attribute;
    		}
    	}
    	}
    	return '';
    },
    //------------生成编辑属性--------------------------------------------
    initEditJSONHiedInput : function(a,i,v){
    	var self = this;
    	var idx = 0;
    	var html =[];
    	var attribute = self.getEditAttribute(a);
    	var value = (undefined == v?'':v);
    	html[idx++]='<input type="hidden" id="nk_'+self.id+'_attribute_'+a+'_'+i+'" value="'+attribute+'"/>';//对应后端的属性
        html[idx++]='<textarea rows="2" cols="2" style="display: none;"   id="nk_'+self.id+'_tdvalue_'+a+'_'+i+'"/>'+value+'</textarea>';//对应后端的属性
        return html.join('');
    },
    //------------给编辑框初始化值------------------------------------------
    initEditValue : function(){
    	var self = this;
    	var editCells = self.editCells;//编辑列配置
    	if(undefined!=editCells && editCells.length>0){
	    	$$('tr[id^="nk_'+self.id+'_dcell_"]').each(function(row,index) {
	    		var cells = row.cells;//列
	    		for(var i=self.syscells.length;i<cells.length;i++){//循环列
	    			var cellidx = self.getRowAndCellIndex(cells[i]);//行号和列号
	    			var rdv = self.cellGetEditValue(cells[i]);
	    			for(var a=0;a<editCells.length;a++){
	    				if(editCells[a].attribute==rdv.attribute){
	    					try{
		    					var vids = 'nk_'+self.id+'_tdvalue_'+cellidx.cellIndex+'_'+cellidx.rowIndex;
		    					var cfg = editCells[a].cfg;
		    					if(cfg.type=='input' || cfg.type=='dateselect' || cfg.type=='minput'){
		    						$(vids).value=$(cells[i].id+'_div').innerHTML.hTrim();
		    					}else if(undefined != cfg.vid){
		    						$(vids).value=self.getCellTd(cellidx.rowIndex,cfg.vid).innerHTML.hTrim();
		    					}
	    					}catch(e){}
	    				}
	    			}
	    		}
	    	});
    	}
    },
    //------------获取dbgrid所有数据---------------------------------------
    getGridData : function(){//[]
    	var self = this;
    	var dbdata = [];
    	if(self.showcell){
    		$$('div[id^="nk_'+self.id+'_dcell_"]').each(function(row,index) {
    			try{
	    			var rdata = $(row.id+'_json').innerHTML.evalJSON();
	    			dbdata.push(rdata);
    			}catch(e){}
    		});
    	}else if(undefined != self.editCells && self.editCells.length>0){//有编辑选项
    		$$('tr[id^="nk_'+self.id+'_dcell_"]').each(function(row,index) {
	    		var rdata = "{";
	    		var cells = row.cells;
	    		for(var i=self.syscells.length;i<cells.length;i++){
	    			var rdv = self.cellGetEditValue(cells[i]);
	    			if(undefined!=rdv.attribute && ''!=rdv.attribute && rdv.value.hTrim().trim().length>0){
	    				rdata+='"'+rdv.attribute+'":'+'"'+rdv.value+'",';
	    			}
	    		}
	    		if(rdata.indexOf(",")!=-1){
	    			rdata = rdata.substring(0,rdata.length-1);
	    		}
	    		rdata+="}";
	    		dbdata.push(rdata.evalJSON());
	    	});
    	}else{
	    	$$('tr[id^="nk_'+self.id+'_dcell_"]').each(function(row,index) {
	    		var rdata = [];
	    		var cells = row.cells;
	    		for(var i=self.syscells.length;i<cells.length;i++){
	    			var rdv = self.cellGetValue(cells[i]);
	    			if(rdv.indexOf('<div ')==-1 && rdv.hTrim().trim().length>0){
	    				rdata[i-self.syscells.length]=rdv;
	    			}
	    		}
	    		dbdata.push(rdata);
	    	});
    	}
    	
    	return dbdata;
    },
    //--------------------获取编辑框验证结果-----------------------------------------------------------
    getInputVri : function(rowIndex){
    	var isVri = true;
    	var self = this;
    	var id =self.id;
    	if(undefined!=rowIndex){
    		id+='_dcell_'+rowIndex;
    	}else{
    		id=self.target;
    	}
    	$$('#'+id+' div[class~=nk_input_sdDiv]').each(function(row,index) {
    		isVri = false;
    		return;
    	});
    	return isVri;
    },
    //===========获取当前选中行对对象,只对在单选状态下有效==========================
    getSelectRow : function(){
    	var self = this;
    	var syscells = self.syscells;
    	var obj = undefined;
    	if(self.showcell){//多列显示
    		$$('div[id^="nk_'+self.id+'_dcell_"]').each(function(row,index) {
        		var checkBox = $(row.id+'_checkbox');
        		try{
        			if(checkBox!=undefined && (checkBox.type=='checkbox' || checkBox.type=='radio') &&  checkBox.checked){
        				obj = $(row.id);
        				return obj;
        			}
        		}catch(e){}
        	});
    	}else{
    		$$('tr[id^="nk_'+self.id+'_dcell_"]').each(function(row,index) {
    			for(var a=0;a<syscells.length;a++){
        			if(4==syscells[a].type || 3==syscells[a].type){//单选或多选
        				try{
        					var row_index = self.getRowIndex(row);//行号
        					var checkbox = $('nk_'+self.id+'_dcell_'+a+'_'+row_index+'_checkbox');
        					if(checkbox.checked){
        						obj =  self.RowCreateFunction($('nk_'+self.id+'_dcell_'+row_index));//行对象
        						return obj;
            				}
        				}catch(e){}
        			}
        		}
    		});
    	}
    	return obj;
    },
    //==========================获取选择行，返回数组=============================================
    getSelectRows : function(){
    	var self = this;
    	var syscells = self.syscells;
    	var idx = 0;
    	var obj = [];
    	if(self.showcell){//多列显示
    		$$('div[id^="nk_'+self.id+'_dcell_"]').each(function(row,index) {
        		var checkBox = $(row.id+'_checkbox');
        		try{
        			if(checkBox!=undefined && (checkBox.type=='checkbox' || checkBox.type=='radio') &&  checkBox.checked){
        				obj[idx++] = $(row.id);
        			}
        		}catch(e){}
        	});
    	}else{
    		$$('tr[id^="nk_'+self.id+'_dcell_"]').each(function(row,index) {
    			for(var a=0;a<syscells.length;a++){
        			if(4==syscells[a].type || 3==syscells[a].type){//单选或多选
        				try{
        					var row_index = self.getRowIndex(row);//行号
        					var checkbox = $('nk_'+self.id+'_dcell_'+a+'_'+row_index+'_checkbox');
        					if(checkbox.checked){
        						obj[idx++]=self.RowCreateFunction($('nk_'+self.id+'_dcell_'+row_index));//行对象
            				}
        				}catch(e){}
        			}
        		}
    		});
    	}
    	return obj;
    },
    //===========删除行=================================================
    deleteDataRow : function(){
    	var self = this;
    	var syscells = self.syscells;
    	if(self.showcell){
    		self.deleteDataRowDiv();
    		return;
    	}
    	$$('tr[id^="nk_'+self.id+'_dcell_"]').each(function(row,index) {
    		for(var a=0;a<syscells.length;a++){
    			if(4==syscells[a].type || 3==syscells[a].type){//单选或多选
    				try{
    					var row_index = self.getRowIndex(row);//行号
    					var checkbox = $('nk_'+self.id+'_dcell_'+a+'_'+row_index+'_checkbox');
    					if(checkbox.checked){
    						self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+row_index),'del');
        					$('nk_'+self.id+'_dcell_'+row_index).remove();//删除
        				}
    				}catch(e){}
    			}
    		}
    	});
    	$$('tr[id^="nk_'+self.id+'_left_dcell_"]').each(function(row,index) {
    		for(var a=0;a<syscells.length;a++){
    			if(4==syscells[a].type || 3==syscells[a].type){//单选或多选
    				try{
    					var row_index = self.getRowIndex(row);//行号
    					var checkbox = $('nk_'+self.id+'_left_dcell_'+a+'_'+row_index+'_checkbox');
    					if(checkbox.checked){
    						self.editAjaxSubmit($('nk_'+self.id+'_left_dcell_'+row_index),'del');
        					$('nk_'+self.id+'_left_dcell_'+row_index).remove();//删除
        				}
    				}catch(e){}
    			}
    		}
    	});
    	self.initFxiedData();
    },
    //===================根据给定的列和值匹配删除，多个值用逗号分隔===================
    deleteDataRowFilter : function(cellname,value){
    	var self = this;
    	var values = ','+value+',';
    	$$('tr[id^="nk_'+self.id+'_dcell_"]').each(function(row,index) {
    		var row_index = self.getRowIndex(row);//行号
    		var va = self.getCellTd(row_index,cellname).innerHTML.hTrim();
    		if(values.indexOf(','+va+',')!=-1){
    			$('nk_'+self.id+'_dcell_'+row_index).remove();//删除
    		}
    	});
    },
    deleteDataRowDiv : function(){
    	var self = this;
    	$$('div[id^="nk_'+self.id+'_dcell_"]').each(function(row,index) {
    		var checkBox = $(row.id+'_checkbox');
    		try{
    			if(checkBox!=undefined && (checkBox.type=='checkbox' || checkBox.type=='radio') && checkBox.checked){
    				self.editAjaxSubmit(row,'del');
    				$(row.id).remove();
    			}
    		}catch(e){}
    	});
    },
    //---------------------根据行对像，取得行号----------------------------------
    getRowIndex : function(row){
    	return row.id.substring(row.id.lastIndexOf('_')+1,row.id.length);//行号
    },
    //---------------------重组行对我----------------------------------------
    RowCreateFunction : function(row){
    	var self = this;
    	if(row!=undefined){
    		row.getCheck = function(){//获取选择框对象
    			var checkBox = undefined;
    			$$('#'+row.id+' input').each(function(alink,index){
    				if(alink.type=='checkbox' || alink.type=='radio'){
    					checkBox = alink;
    					return;
    	    		}	
    			});
    			return checkBox;
    		};
    		row.getRowData = function(){//获取整行数组，返回[],不包含系统列
    			var cells = row.cells;
    			var rdata = [];
        		for(var i=self.syscells.length;i<cells.length;i++){
        			var rdv = self.cellGetValue(cells[i]);
        			if(rdv.indexOf('<div ')==-1){
        				rdata[i-self.syscells.length]=rdv;
        			}
        		}
        		return rdata;
    		};
    		row.getCell = function(index){//获取某一单元格对象
    			var cell = self.getCellTd(self.getRowIndex(row),index);
    			cell.getValue = function(){//获取单元格值
    				return $(cell.id).innerHTML.hTrim();
    			};
    			cell.setValue = function(value){//设置单元格值
    				$(cell.id).innerHTML=value.replace(/\n/g,'');
    				try{
    					$('nk_'+self.id+'_tdvalue_'+index+'_'+self.getRowIndex(row)).value=value.replace(/\n/g,'');
    				}catch(e){
    				}
    			};
    			return cell;
    		};
    	}
    	return row;
    },
    //--------------重新生成dbgrid-----------------------------------------
    ReCreateDbgrid : function(sql,cells){
    	var self = this;
    	self.sql = (undefined!=sql?sql:self.sql);
    	self.showpage=1;
    	self.options.pagedescorname='';
    	self.options.pagedescorasc='';
    	$(self.options.checkrecord).value='';//清空翻页记录
    	self.getCellModelAjax(cells);//获取新的列名
    },
    //-----------------根据sql获取取列名--------------------------------------
    getCellModelAjax : function(cells){
    	var self = this;
    	var idx  = 0;
    	var pars = [];
    	pars[idx++]='&ng=1';
    	pars[idx++]='&sql='+self.sql;
    	if(cells!=undefined)
    		pars[idx++]='&cells='+encodeURIComponent(cells);
    	new Ajax.Request(self.dataurl, {
            parameters: pars.join(''),
            method:'post',
            onSuccess: function(response) {
            	self.columnModel = response.responseText.evalJSON();
            	self.show('div_'+self.id);
            },
            onFailure : function(response) {
	        }
    	});
    },
    //-------------设置可编辑列----------------------------------------------
    setEditCell : function(editCells){
    	this.editCells = editCells;
    },
    //-------------显示/隐藏列---------------------------------------------
    setCellVisible : function(index,vis){
    	var self = this;
    	var cindex = self.cellNameToIndex(index);//返回列号
    	self.CellShowOrHide(cindex,!vis);
    },
    //-------------方向键处理方法-------------------------------------------
    keypressutil : function(event) {
    	var self=this;
    	var e = Event.element(event);
		if(e.id!=undefined && e.id.startsWith('nk_'+self.id+'_dcell_') && undefined != self.editCells && self.editCells.length>0){//只响自己的
			//-------------判断方向键---------------------------------------------------
			var maxCellIndex = self.editCells.length-1;//最大可编辑列号
			var maxRowIndex = self.rowNumber-1;//最大行号
			
	        switch(event.keyCode){
		       case 37://左
		         self.editNowCellRow.cellIndex--;
		    	 break;
		       case 38://上
		         self.editNowCellRow.rowIndex--;
		         break;
		       case 39://右
		         self.editNowCellRow.cellIndex++;
		         break;
		       case 40://下
		         self.editNowCellRow.rowIndex++;
		         break;
		       case 13://回车键
		    	   Event.stop(event);//禁用回车键
		    	 break;
	        }
	        //------------生成编辑单元格--------------------------------------------------
	        if(self.editNowCellRow.cellIndex<0){
	        	self.editNowCellRow.cellIndex=0;
	        }
	        if(self.editNowCellRow.cellIndex>maxCellIndex){
	        	self.editNowCellRow.cellIndex=maxCellIndex;
	        }
	        if(self.editNowCellRow.rowIndex<0){
	        	self.editNowCellRow.rowIndex=0;
	        }
	        if(self.editNowCellRow.rowIndex>maxRowIndex){
	        	self.editNowCellRow.rowIndex =maxRowIndex;
	        }
	        var rcIndex = self.editNowCellRow;//获取列号，行号
	        var editCellIndex = self.cellNameToIndex(self.editCells[rcIndex.cellIndex].cell);//找出实际的编辑列号
			var cfg = self.editCells[rcIndex.cellIndex].cfg;
			var bod = $('nk_'+self.id+'_dcell_'+editCellIndex+'_'+rcIndex.rowIndex);//单元格对象
			//-----------------------外部初始化方法------------------------------------
			if(!self.onedituser(this,self.editCells[rcIndex.cellIndex].oninitedit)){//单元格对象,事件
				return;
			}
			//--------------------------------------------------------------------
			if('input'==cfg.type)
				self.inputTextCreate(bod,cfg);//普通录入框
			else if('minput'==cfg.type)
				self.minputTextCreate(bod,cfg);//多项录入框
			return;
		}
    },
    //------------编辑时使用方向键-------------------------------------------
    keypressEvent : function(){
    	var self=this;
    	if(self.keyutilfunction!=undefined){
    		Event.stopObserving(document, 'keydown',self.keyutilfunction);
    	}
    	self.keyutilfunction = self.keypressutil.bindAsEventListener(self); 
    	if(self.editCells!=undefined && self.editCells.length>0){//有编辑列
    		Event.observe(document, "keydown",self.keyutilfunction);
    	}
    },
    //------------重设表体高度-----------------------------------------------
    reSetBodyHeight : function(){
    	var self = this;
    	//if(self.autosize){
	    	var bheight = $('nk_'+self.id+'_data_div').getHeight();
	    	var custom  = $('nk_'+self.id+'_custom_div');
	    	var cuheight = (undefined==custom?0:custom.getHeight());
	    	var title  = $('nk_'+self.id+'_select_div');
	    	var theight = (undefined==title?0:title.getHeight());
	    	var gheight = $(self.target).getHeight();
	    	if(gheight>bheight){
	    		var xheight = bheight-(gheight- bheight-cuheight)-theight;
	    		$('nk_'+self.id+'_data_div').setStyle({height: xheight+'px'});
	    	}
    	//}
    },
    //------------设置表格大小----------------------------------------------
    setWidthAndHeight : function(ws,hs){//setSize(w,h)
    	var self = this;
    	var w =$('nk_'+self.id+'_size_width').getWidth()-ws-2;
    	var h=$('nk_'+self.id+'_size_height').getHeight()-hs-2;
    	self.setGridWidthAndHeight(w,h);
    },
    //-----------------------------------------------------------------
    setGridWidthAndHeight : function(ws,hs){//setSize(w,h)
    	var self = this;
    	var pw =$('nk_'+self.id+'_size_width').getWidth()-2;
    	var ph=$('nk_'+self.id+'_size_height').getHeight()-2;
    	var top = $('div_'+self.id).positionedOffset().top;
    	var w = (undefined!=ws?ws:pw);
    	var h = (undefined!=hs?hs:ph);
    	if(w<10){
    		w = pw;
    	}
    	if(h<10){
    		h=ph;
    	}
    	setTimeout(function(){
    		self.setHeight(h-top-8);//设置高度
    	}, 10);
    	self.setWidth(w);//设置宽度   
    	setTimeout(function(){
    		self.initFexed();//初始化固定列
    		self.initFxiedData();
    	},10);
    	//--------------------------------------------------------------
    	if(!self.isAginSize){
	    	var wp = $(self.target).getWidth();
	    	var wh = $(self.target).getHeight();
	    	if(wp<self.width || wh<self.heigth){//最多只做两次设置大小
	    		setTimeout(function(){
	    			self.isAginSize = true;
	    			self.setWidthAndHeight(0,0);
	    		}, 200);
	    	}
    	}
    	self.setMenuInit();
    },
    //-----------设置宽度--------------------------------------------------
    setWidth : function(w){
    	var self = this;
    	 $(self.target).setStyle({width: w+'px'});
    	 try{$('nk_'+self.id+'_title_div').setStyle({width: w+'px'});}catch(e){}
    	 try{$('nk_'+self.id+'_title_table').setStyle({width: w+'px'});}catch(e){}
    	 try{$('nk_'+self.id+'_head_div').setStyle({width: w+'px'});}catch(e){}
    	 try{$('nk_'+self.id+'_data_div').setStyle({width: w+'px'});}catch(e){}
    	 //try{$('nk_'+self.id+'_data_table').setStyle({width: w+'px',tableLayout:'fixed'});}catch(e){}
    	 try{$('nk_'+self.id+'_select_div').setStyle({width: w+'px'});}catch(e){}
    	 try{$('nk_'+self.id+'_sumcells_div').setStyle({width: w+'px'});}catch(e){}
    	 self.resetoverflowx();
    	 self.width =w;
    },
    //-----------重设横向滚动条----------------------------------------------
    resetoverflowx : function(){
    	var self = this;
    	 try{
    		 var dwidth = $('nk_'+self.id+'_data_div').getWidth();//1902
    		 var twidth = $('nk_'+self.id+'_data_table').getWidth();//1914
    		 if(twidth-dwidth<18){
    			 $('nk_'+self.id+'_data_div').setStyle({overflowX:'hidden'});
    		 }else{
    			 $('nk_'+self.id+'_data_div').setStyle({overflowX:'scroll'});
    		 }
    	 }catch(e){}
    },
    //-----------设置高度--------------------------------------------------
    setHeight : function(h){
    	var self = this;
    	var titleHeight=0;//$('nk_'+self.id+'_title_div').getHeight();
    	try{titleHeight=$('nk_'+self.id+'_title_div').getHeight();}catch(e){}
    	var headHeight=$('nk_'+self.id+'_head_div').getHeight();
    	var bootomHeight=$('nk_'+self.id+'_bottom_div').getHeight();
    	var custom  = $('nk_'+self.id+'_custom_div');
    	var cuheight = (undefined==custom?0:custom.getHeight());
    	var sumcells  = $('nk_'+self.id+'_sumcells_div');
    	var sumheight = (undefined==sumcells?0:sumcells.getHeight());
    	titleHeight=(undefined==titleHeight?0:titleHeight);
    	headHeight=(undefined==headHeight?0:headHeight);
    	bootomHeight=(undefined==bootomHeight?0:bootomHeight);
    	var pheight=(h-titleHeight-headHeight-bootomHeight-cuheight-sumheight);
    	$('nk_'+self.id+'_data_div').setStyle({height:pheight+'px'});
    	self.heigth = pheight;
    },
    //============查入行===================================================
    insertDataRow : function(rowDate,rowindx){//行数据,行号
    	var self = this;
    	var dbtable = $('nk_'+self.id+'_data_table');
    	var Ldbtable = $('nk_'+self.id+'_left_data_table');
    	var toprow = (undefined==rowindx?undefined:self.getRowObject(rowindx));
    	var Ltoprow = (undefined==rowindx?undefined:self.getRowLeftObject(rowindx));
    	var idx = 0;
        var html = [];
        var Ldx = 0;
        var Ltml = [];
        var i=-1;
        var sysWidth = 0;
        var pclass = '';
        var lineHide=(self.foldingLine?'':'data_foldingline');//true 折行显示
        if(self.showcell){//多列显示
        	return self.insertDataRowDiv(rowDate);
        }
    	if(self.noData){
    	 html[idx++]='<table id="nk_'+self.id+'_data_table"    border="0"  cellpadding="0" cellspacing="0"  class="nk_data_table">';
    	 html[idx++] = '<tbody>';
    	 Ltml[Ldx++] = '<div id="nk_'+self.id+'_left_data_div" class="nk_fxeid_style" style="display:none;position:fixed;top:0px;left:0px;z-index:99;overflow:hidden;width:{divwidth}px;">';
         Ltml[Ldx++] = '<table id="nk_'+self.id+'_left_data_table" border="0"  cellpadding="0" cellspacing="0"  class="nk_data_table">';
         Ltml[Ldx++] = '<tbody>';
    	}
    	if(dbtable!=undefined){//有表格
            i =self.rowNumber;
            try{
            	pclass = $('nk_'+self.id+'_dcell_'+rowindx).className;}catch(e){}
            if(undefined!=pclass && pclass.trim().length>0){
            	pclass +=rowindx+'_'; 
            }else{
            	pclass='pclassid_'+rowindx+'_';
            }
            var lnwidth = pclass.split('_').length;
            var leftSx = (lnwidth<4?2:lnwidth)*8;
            var divtemp='<div id="{id}_div" width="{width}px" class="'+lineHide+'" style="width:{width}px;margin: 0 atuo;padding: 0;">';
            html[idx++]='<tr id="nk_'+self.id+'_dcell_'+i+'" 	  class="'+pclass+'">';
            Ltml[Ldx++]='<tr id="nk_'+self.id+'_left_dcell_'+i+'" class="'+pclass+'">';
            var syscells = self.syscells;
            var cells=this.columnModel;
            var classStyle=self.getAirLenClassStyle(cells,rowDate, i);
            for(var a=0;a<syscells.length;a++){
            	var scwidth=syscells[a].width;//Prototype.Browser.WebKit
            	var isShow=(syscells[a].show==1 || syscells[a].show==2)?"display:'';":"display:none;";
            	var checkname=(''==self.options.checkname?'nk_'+self.id+'_checkdata':self.options.checkname);
            	var isSelect= '';
            	sysWidth+= scwidth;
            	classStyle=self.getAirLenClassStyle(cells,rowDate, i);
            	switch(syscells[a].type){//1 子表    2 序号  3 单选  4 多选    5 数据列
                case 1://子表
                	html[idx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_dcell_'+a+'_'+i+'"      width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
                	Ltml[Ldx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_left_dcell_'+a+'_'+i+'" width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
                	html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_dcell_'+a+'_'+i);
                	Ltml[Ldx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_left_dcell_'+a+'_'+i);
                	html[idx++]='<span><img  id="nk_'+self.id+'_dcell_subimage_'+a+'_'+i+'" src="'+self.url+'/tablegrid/images/plus_table.gif" title="" alt="" class="nk_sub_images"></span>';
                	Ltml[Ldx++]='<span><img  id="nk_'+self.id+'_left_dcell_subimage_'+a+'_'+i+'" src="'+self.url+'/tablegrid/images/plus_table.gif" title="" alt="" class="nk_sub_images"></span>';
                	html[idx++]='</div></td>';
                	Ltml[Ldx++]='</div></td>';
                	isSubTable=true;
             		break;
                case 2://序号
                	html[idx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_dcell_'+a+'_'+i+'"      width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
                	Ltml[Ldx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_left_dcell_'+a+'_'+i+'" width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
                	html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_dcell_'+a+'_'+i);
                	Ltml[Ldx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_left_dcell_'+a+'_'+i);
                	html[idx++]=(i+1)+'</div></td>';
                	Ltml[Ldx++]=(i+1)+'</div></td>';
                	break;
                case 3://单选radio
                	html[idx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_dcell_'+a+'_'+i+'"      width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
                	Ltml[Ldx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_left_dcell_'+a+'_'+i+'" width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
                	html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_dcell_'+a+'_'+i);
                	Ltml[Ldx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_left_dcell_'+a+'_'+i);
                	html[idx++]='<input type="radio" '+isSelect+' name="'+checkname+'" id="nk_'+self.id+'_dcell_'+a+'_'+i+'_checkbox"      class="nk_input_check" value="'+(rowDate==undefined?'-1':rowDate[0])+'"></input>';
                	Ltml[Ldx++]='<input type="radio" '+isSelect+' name="'+checkname+'" id="nk_'+self.id+'_left_dcell_'+a+'_'+i+'_checkbox" class="nk_input_check" value="'+(rowDate==undefined?'-1':rowDate[0])+'"></input>';
                	html[idx++]='</div></td>';
                	Ltml[Ldx++]='</div></td>';
                	break;
                case 4://多项选择列
                	html[idx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_dcell_'+a+'_'+i+'"      width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
                	Ltml[Ldx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_left_dcell_'+a+'_'+i+'" width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
                	html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_dcell_'+a+'_'+i);
                	Ltml[Ldx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_left_dcell_'+a+'_'+i);
                	html[idx++]='<input type="checkbox" '+isSelect+' name="'+checkname+'"  id="nk_'+self.id+'_dcell_'+a+'_'+i+'_checkbox"      class="nk_input_check" value="'+(rowDate==undefined?'-1':rowDate[0])+'"></input>';
                	Ltml[Ldx++]='<input type="checkbox" '+isSelect+' name="'+checkname+'"  id="nk_'+self.id+'_left_dcell_'+a+'_'+i+'_checkbox" class="nk_input_check" value="'+(rowDate==undefined?'-1':rowDate[0])+'"></input>';
                	html[idx++]='</div></td>';
                	Ltml[Ldx++]='</div></td>';
                	$('nk_'+self.id+'_check_all').checked=false;
                	try{$('nk_'+self.id+'_left_check_all').checked=false;}catch(e){}
             		break;
                case 5://树形表
                	html[idx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_dcell_'+a+'_'+i+'"      width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
                	Ltml[Ldx++]='<td class="'+classStyle+'" id="nk_'+self.id+'_left_dcell_'+a+'_'+i+'" width="'+syscells[a].width+'px"  style="'+isShow+'width:'+syscells[a].width+'px;word-break:break-all;" >';
                	html[idx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_dcell_'+a+'_'+i);
                	Ltml[Ldx++]=divtemp.replace(/\{width\}/g,scwidth).replace(/\{id\}/g,'nk_'+self.id+'_left_dcell_'+a+'_'+i);
                	html[idx++]='<span style="padding-left:'+leftSx+'px;"><img  id="nk_'+self.id+'_dcell_treeimage_'+a+'_'+i+'"      src="'+self.url+'/tablegrid/images/plus_table.gif" title="" alt="" class="nk_sub_images"></span>';
                	Ltml[Ldx++]='<span style="padding-left:'+leftSx+'px;"><img  id="nk_'+self.id+'_left_dcell_treeimage_'+a+'_'+i+'" src="'+self.url+'/tablegrid/images/plus_table.gif" title="" alt="" class="nk_sub_images"></span>';
                	html[idx++]='</div></td>';
                	Ltml[Ldx++]='</div></td>';
                	isSubTable=true;
             		break;
            	}
            }
            for(var a=0;a<cells.length;a++){//列
            	var isShow=(cells[a].show==1 || cells[a].show==2)?"display:'';":"display:none;";
            	classStyle=self.getAirLenClassStyle(cells,rowDate, i);
            	var dataValue=((undefined==rowDate || rowDate[cells[a].name]==undefined)?'':rowDate[cells[a].name]);
            	var dcwidt=cells[a].width;
            	sysWidth+=(cells[a].fixed?cells[a].width:0);
            	if(undefined!=cells[a].aircell){
                	for(var s=0;s<cells[a].aircell.length;s++){
                		if(rowDate[cells[a].name]==cells[a].aircell[s].key){
                			classStyle=cells[a].aircell[s].cl;
                			break;
                		};
                	};
            	}
            	if(undefined!=self.editCells){
            		for(var s=0;s<self.editCells.length;s++){
            			if(cells[a].name == self.editCells[s].cell){
            				classStyle='data_cell_edit';
            				break;
            			}
            		}
            	}
                html[idx++]='<td width="'+cells[a].width+'" style="'+isShow+'width:'+cells[a].width+'px;" class="'+classStyle+'"  id="nk_'+self.id+'_dcell_'+(a+syscells.length)+'_'+i+'" >';
                Ltml[Ldx++]='<td width="'+cells[a].width+'" style="'+isShow+'width:'+cells[a].width+'px;" class="'+classStyle+'"  id="nk_'+self.id+'_left_dcell_'+(a+syscells.length)+'_'+i+'" >';
            	html[idx++]=divtemp.replace(/\{width\}/g,(dcwidt)).replace(/\{id\}/g,'nk_'+self.id+'_dcell_'+(a+syscells.length)+'_'+i);
            	Ltml[Ldx++]=divtemp.replace(/\{width\}/g,(dcwidt)).replace(/\{id\}/g,'nk_'+self.id+'_left_dcell_'+(a+syscells.length)+'_'+i);
                html[idx++]=dataValue+'</div>';
                Ltml[Ldx++]=dataValue+'</div>';
                //-------------------------------------------------------------------------
                html[idx++]=self.initEditJSONHiedInput((a+syscells.length),i,dataValue); 
                Ltml[Ldx++]=self.initEditJSONHiedInput((a+syscells.length),i,dataValue); 
                //-------------------------------------------------------------------------
                html[idx++]='</td>';
                Ltml[Ldx++]='</td>';
            }
            html[idx++]='</tr>';
            Ltml[Ldx++]='</tr>';
            if(self.noData){//没有表格
            	html[idx++] = '</tbody>';
            	Ltml[Ldx++]='</tbody>';
                html[idx++]='</table>';
                Ltml[Ldx++]='</table>';
                Ltml[Ldx++]='</div>';
                var fxiedHtml = Ltml.join('').replace(/\{width\}/g,(self.GetDataBodyWidth())).replace(/\{divwidth\}/g,sysWidth);
                $('nk_'+this.id+'_data_div').innerHTML=fxiedHtml+html.join('').replace(/\{width\}/g,(self.GetDataBodyWidth()));
           	}else{
           		if(undefined!=toprow){
           			toprow.insert({after:html.join('')});
           			Ltoprow.insert({after:Ltml.join('')});
           		}else{
           			dbtable.insert(html.join(''));
           			Ldbtable.insert(Ltml.join(''));
           		}
           	}
    		self.initFxiedData();
    		self.DataRowSelect();//加载行事件
    		self.TreeTableUtilIndex(i);
    		//------------------------------------------------------
        	setTimeout(function(){
        		self.initEditValue();
        	},10);
    		self.rowNumber+=1;//总数加1
    		self.noData = false;
    		if(rowDate!=undefined){//有数据时，调用增加行方法
    			self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+i),'add');//添加
    		}else{
    			self.editAddNowHash.set('nk_'+self.id+'_dcell_'+i,true);//记录新增行，并且该行没有被提交过
    		}
    		if(i>-1){
            	return $('nk_'+self.id+'_dcell_'+i);//返回插入的行对象
            }
            return undefined;
    	}
    },
    insertDataRowDiv : function(rowDate){
    	var self = this;
    	var idx = 0;
        var html = [];
        var dbtable = $('nk_'+self.id+'_data_table');
        var i= -1;
        if(rowDate!=undefined){//有数据
        	var row=rowDate;
        	i =self.rowNumber;
        	var cells=self.columnModel;
        	var dataBody=$('nk_'+self.id+'_data_div');
    		var cellBody = $(self.id+'_cell_body_div').innerHTML;
    		var checkvalue=(''==self.options.checkvalue?0:parseInt(self.options.checkvalue));
        	var checkname=(''==self.options.checkname?'nk_'+self.id+'_checkdata':self.options.checkname);
        	var selectValue = ','+$(self.options.checkrecord).value+',';//选择列
            var textColor= (''==self.options.textColor?'#FFFFFF':self.options.textColor);
         	var backgroundColor=(''==self.options.backgroundColor?'#09C':self.options.backgroundColor);
        	var isSelect= selectValue.indexOf(','+row[checkvalue]+',')==-1?'':'checked="checked"';
        	var isSelectStyle= selectValue.indexOf(','+row[checkvalue]+',')==-1?'':'color:'+textColor+';background-Color:'+backgroundColor;
        	try{
        		dbtable.remove();
    		}catch(e){}
        	html[idx++] = '<div id="nk_'+self.id+'_dcell_'+i+'"  style="float: left;'+isSelectStyle+'" class="nk_user_cell_div">';
    		for(var a=0;a<cells.length;a++){//列
    			var a_n = '\\{'+a+'\\}';
    			var a_s = '\\{'+cells[a].name+'\\}';
    			try{cellBody = cellBody.replace(new RegExp(a_n,'g'),(row[cells[a].name]==undefined?'':row[cells[a].name]));}catch(e){}//替换数据
    			try{
    				if(row[cells[a].name]!=undefined){
    					cellBody = cellBody.replace(new RegExp(a_s,'g'),(row[cells[a].name]==undefined?'':row[cells[a].name]));
    				}
    			}catch(e){}//替换数据
    		}
    		cellBody=cellBody.replace(/\{usercellid\}/g,'nk_'+self.id+'_dcell_'+i);//替换id
    		cellBody=cellBody.replace(/\{row_no_id\}/g,i);//替换行序号变量
    		cellBody=cellBody.replace(/\{row_id\}/g,'nk_'+self.id+'_dcell');//替换行id变量，不包含行序号
    		html[idx++] = cellBody;
    		html[idx++] = '<div id="nk_'+self.id+'_dcell_'+i+'_json" style="display: none;">'+Object.toJSON(row)+'</div>';
    		if(self.options.checkd!=undefined && (self.options.checkd=='checkbox' || self.options.checkd=='radio')){
    			html[idx++] = '<div><input type="'+self.options.checkd+'" '+isSelect+' name="'+checkname+'"  id="nk_'+self.id+'_dcell_'+i+'_checkbox" class="nk_input_check" value="'+row[checkvalue]+'" disabled="disabled"></div>';
    		}else{
    			html[idx++] = '<div style="display:none;"><input type="radio" '+isSelect+' name="'+checkname+'"  id="nk_'+self.id+'_dcell_'+i+'_checkbox" class="nk_input_check" value="'+row[checkvalue]+'" disabled="disabled"></div>';
    		}
    		html[idx++] = '</div>';
    		dataBody.insert(html.join(''));
    		self.DataRowSelect();//加载行事件
    		self.rowNumber+=1;//总数加1
    		if(rowDate!=undefined){//有数据时，调用增加行方法
    			self.editAjaxSubmit($('nk_'+self.id+'_dcell_'+i),'add');//添加
    		}else{
    			self.editAddNowHash.set('nk_'+self.id+'_dcell_'+i,true);//记录新增行，并且该行没有被提交过
    		}
        }
        if(i>-1){
        	return $('nk_'+self.id+'_dcell_'+i);
        }
        return undefined;
    },
    //----------------获取外部表单的值-------------------------------------------------
    GetFormPars : function(traget){
    	var idx=0;
    	var pars=[];
    	var b=true;
    	var repas={vri:false,data:''};//返回的数据
    	$$('#'+traget+' input,select,textarea').each(function(alink,index) {
    		//-------------验证-------------------------------------------------
    		try{
    			if(b)
    				b=alink.veri();
    			else
    				alink.veri();
    		}catch(e){}
    		//------------------------------------------------------------------
    		if(alink.type=='checkbox' || alink.type=='radio'){
    			if(alink.checked)
    				pars[idx++]='&'+alink.name+'='+alink.value;//alert(alink.name);
    		}else if(alink.value.hTrim().trim().length>0){
    			pars[idx++]='&'+alink.name+'='+encodeURIComponent(alink.value);//alert(alink.name);
    		}
		});
    	if(b){//验证通过提交
    		repas.vri=true;//验证通过
    		repas.data = pars.join('');
    		return repas;
    	}
    	return repas;
    },
    //----------------格式化时间--------------------------------------------------
    formdates : function(date,fmt){
    	if(undefined == date || date.trim().length<1 || date.hTrim().length<1){
            return '';
        }
    	if(undefined == fmt || fmt.trim().length<1){
    		return date;
    	}
    	try{
    		var sc = date.replace(/-/g, "/");
    		if(-1!=sc.indexOf('.')){
    			sc = sc.substring(0,sc.indexOf('.'));
    		}
    		date = new Date(Date.parse(sc));
    		return date.Format(fmt);
    	}catch(e){
    	}
    	return date;
    },
    //-----------------保存列信息到数据库--------------------------------------------
    saveCellMode : function(){
    	var self = this;
    	var pars=[];
    	var idx=0;
    	if(undefined!=self.setkey){
	    	pars[idx++]='nkdbgridkey='+self.setkey;
	    	pars[idx++]='&nkdbgridcells='+Object.toJSON(self.columnModel);
	    	new Ajax.Request(self.dataurl, {
	            parameters: pars.join(''),
	            method:'post',
	            onSuccess: function(response) {
	            }
	    	});
    	}
    },
    //-----------------清除列信息到数据库--------------------------------------------
    ClearCellMode : function(){
    	var self = this;
    	var pars=[];
    	var idx=0;
    	if(undefined!=self.setkey){
	    	pars[idx++]='nkdbgridkey='+self.setkey;
	    	new Ajax.Request(self.dataurl, {
	            parameters: pars.join(''),
	            method:'post',
	            onSuccess: function(response) {
	            }
	    	});
    	}
    	self.columnModel = self.colinitModel;
    	self.autowidth = self.oautowidth;
    	self.show(self.target);
    },
    //-----------------保存折行到数据库--------------------------------------------
    saveFoldingLine : function(isadd){
    	var self = this;
    	var pars=[];
    	var idx=0;
    	if(undefined!=self.setkey){
	    	pars[idx++]='nkdbgridkey='+self.setkey;
	    	pars[idx++]='&foldingline='+isadd;
	    	new Ajax.Request(self.dataurl, {
	            parameters: pars.join(''),
	            method:'post',
	            onSuccess: function(response) {
	            }
	    	});
    	}
    }
});